Send Fax doesn't work - I get the error: "Unsupported Media Type"
Tags: rest api
Feb 11, 2016 at 4:23am • 3 replies • 0 likes
maritza-rico
I use java to send a fax via the RingCentral Fax API. However I got HTTP 415 error code. I really have no idea how to make it work.
public void sendFax(String body, String...toList) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(baseUrl + URI_FAX); httpPost.addHeader("Content-Type", "multipart/mixed; boundary=Boundary_1_6506429161_101"); httpPost.addHeader("Authorization", "Bearer " + rcoAuthResp.getAccess_token()); try { List < RCPhone > list = new ArrayList < > (); for (String to: toList) { list.add(RCPhone.builder().phoneNumber(to).build()); } String requestBody = mapper.writeValueAsString(RCFaxPayload.builder().to(list).faxResolution("High").build()); FormBodyPart bodyPart1 = FormBodyPartBuilder.create() .setName("json") .setBody(new StringBody(requestBody, ContentType.APPLICATION_JSON)) .build(); bodyPart1.getHeader().removeFields("Content-Disposition"); bodyPart1.getHeader().removeFields("Content-Transfer-Encoding"); bodyPart1.getHeader().removeFields("Content-type"); bodyPart1.addField("Content-type", "application/json"); FormBodyPart bodyPart2 = FormBodyPartBuilder.create() .setName("body") .setBody(new StringBody(body, ContentType.TEXT_PLAIN)) .build(); bodyPart2.getHeader().removeFields("Content-Disposition"); bodyPart2.getHeader().removeFields("Content-Transfer-Encoding"); bodyPart2.getHeader().removeFields("Content-type"); bodyPart2.addField("Content-type", "text/plain"); HttpEntity entity = MultipartEntityBuilder .create() .setBoundary("Boundary_1_6506429161_101") .addPart(bodyPart1) .addPart(bodyPart2) .build(); httpPost.setEntity(entity); httpPost.getEntity().writeTo(System.out); String response = processHttpResp(httpClient, httpPost); System.out.println(response); } catch (Exception e) { log.error(e.getMessage(), e); } }
3 Answers
Before putting the implementation in code, the best practicei s to check if it is working in API. You need to log into API explorer here and test the ringcentral fax API to confirm if it's working for you. After that you can call it from you code.
415 http error means media type not supported, which means the content-type you are setting is not correct
0
Please have a look at this code.. https://github.com/vyshakhbabji/ringcentral-java/blob/master/src/utils/SendFax.java This will help you send faxes.
Also, you could make use of the unofficial JAVA SDK for your development. If you have any concerns or questions do let me know and I can hep you out with the development
Also, you could make use of the unofficial JAVA SDK for your development. If you have any concerns or questions do let me know and I can hep you out with the development
0
I haven't had time to examine your code in detail, but you can do the following:
Send a fax using the RC API Explorer to verify faxing is working.
Compare your output to the sample output shown here:
faxing text: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefCreateFaxMessage
faxing files: http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/messages/Fax-Messages/#http-request-exam...
Send a fax using the RC API Explorer to verify faxing is working.
Compare your output to the sample output shown here:
faxing text: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefCreateFaxMessage
faxing files: http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/messages/Fax-Messages/#http-request-exam...
0
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder