Description/Error
Am trying to call a post method web service (Rest) to register a participant into a webinar by using JAVA. While calling the web service am getting “Unsupported Media Type” error. So can you help what media types are using in ZOOM.
Am using OkHttp methodology to POST.
How To Reproduce (If applicable)
https://marketplace.zoom.us/docs/api-reference/zoom-api/webinars/webinarregistrantcreate
tommy
(Tommy Gaessler)
December 9, 2019, 8:50pm
2
Hey @divakar.chandran ,
That error usually means the request body JSON is malformed.
Can you please share your code, and request body so I can debug?
Thanks,
Tommy
Thanks for the respose, Here the code.
final OkHttpClient httpClient = new OkHttpClient();
// form parameters
FormBody formBody = new FormBody.Builder()
.add("email", "divakar.chandran@Xyz.com")
.add("first_name", "Divakar")
.add("last_name", "Chandran")
.build();
Request request = new Request.Builder()
.url("https://api.zoom.us/v2/webinars/WebinarID/registrants")
.addHeader("content-type", "application/json")
.addHeader("authorization", "Bearer XYZZCertificationKey")
.post((okhttp3.RequestBody) formBody)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
// Get response body
System.out.println(response.body().string());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tommy
(Tommy Gaessler)
December 10, 2019, 7:38pm
4
Hey @divakar.chandran ,
I see the issue here. You are sending the request body as form data and specifying the “content-type”, "application/json"
header.
You need to either send JSON as the request body, or change the “content-type” from "application/json"
to "multipart/form-data"
.
Info on "multipart/form-data"
:
http, post, http-headers
Updated code for "multipart/form-data"
:
final OkHttpClient httpClient = new OkHttpClient();
// form parameters
FormBody formBody = new FormBody.Builder()
.add("email", "divakar.chandran@Xyz.com")
.add("first_name", "Divakar")
.add("last_name", "Chandran")
.build();
Request request = new Request.Builder()
.url("https://api.zoom.us/v2/webinars/WebinarID/registrants")
.addHeader("content-type", "multipart/form-data")
.addHeader("authorization", "Bearer XYZZCertificationKey")
.post((okhttp3.RequestBody) formBody)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
// Get response body
System.out.println(response.body().string());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Try that and or changing the Form Builder to be a JSON object and let me know if it works!
Thanks,
Tommy