How to post a file in contact's chat using java?

I’m trying to send a file in a contact’s chat using oauth server-to-server token (bearer).
I’ve tried using simple java classes but I always receive 405 Method Not Allowed error.
Here’s my code that uses apache http client.

import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class ZoomNewMultipartFileSend {
	private static final String API_ENDPOINT = "";
	public static void main(String[] args) {
		String token = ZoomApi.getToken();//get a token using oauth server-to-server
		String userId = "my userid";
		String toContact = " userid";
		String filePath = "path to my file with extension";
		try {
			CloseableHttpClient httpClient = HttpClients.createDefault();
			HttpPost uploadFile = new HttpPost(API_ENDPOINT+userId+"/messages/files");
			uploadFile.setHeader(HttpHeaders.AUTHORIZATION,"Bearer "+token);
			MultipartEntityBuilder builder = MultipartEntityBuilder.create();
			File f=new File(filePath);
			builder.addBinaryBody("files",f,ContentType.APPLICATION_OCTET_STREAM, filePath);
			HttpEntity multipart =;
			CloseableHttpResponse response = httpClient.execute(uploadFile);
			HttpEntity responseEntity = response.getEntity();
			<read response>
		}catch(Exception e) {e.printStackTrace();}

Another implementation, still not working. With this I receive 200 response code but I don’t receive anything. i should receive 201 code and message id in responsemesage.

		String accessToken = ZoomApi.getToken();
		String recipientId = "Nsn6KsSNT_Kr6FhZce5WVA"; // Inserisci l'ID del destinatario del messaggio
		File file = new File("u:\\LibroCod.pdf"); // Inserisci il percorso del file che vuoi inviare
		OkHttpClient client = new OkHttpClient.Builder()
		// Crea il body della richiesta multipart
		RequestBody requestBody = new MultipartBody.Builder()
				.addFormDataPart("to_contact", recipientId)
				.addFormDataPart("files", file.getName(), RequestBody.create(file, MediaType.parse("application/pdf")))
		Request request = new Request.Builder()
				.addHeader("Authorization", "Bearer " + accessToken)
				//.addHeader("to_contact", recipientId)
		// Invia la richiesta e ottieni la risposta
		Response response = client.newCall(request).execute();

HI @ced
Thanks for reaching out to the Zoom Developer Forum, I am happy to help here
Have you tried replicating this issue using Postman to confirm that you are generating the Access token correctly and also posting this message correctly?

Hope this helps,

Amazing post, Elisa. I am already able to generate tokens, I use them everyday to send messages to my contacts with api “{userId}/messages” but for some reason I can’t send files. I have tried everything… I receive 200 response that seems good, but I should get 201 with id in response, and I don’t receive anything.

Thanks for confirming this @ced
Could you please confirm that this was working in the past? that you were able to send files?
In the meantime, I will do some troubleshooting on my end.


Tokens are good, but the program is new. I am new to rest and webhooks, I am using the program to send simple richtext messages since a month and they’re working like a charm, but I can’t find a way to make this program to work.

So you have never been able to send files via API @ced ?

Yes, I’m still trying to @elisa.zoom .

After some tries I have found myself a solution…

It seems Zoom has updated its api URL using “file” prefix instead of “api” and now this code is working.