send fax doesn't work, { "message" : "Unsupported Media Type", "errors" : [ ]}

  • 1
  • Problem
  • Updated 3 years ago
I use java to send out fax to ringcentral fax api, however I got http 415 error. 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) {
            String requestBody = mapper.writeValueAsString(RCFaxPayload.builder().to(list).faxResolution("High").build());
            FormBodyPart bodyPart1 = FormBodyPartBuilder.create()
                    .setBody(new StringBody(requestBody, ContentType.APPLICATION_JSON))
            bodyPart1.addField("Content-type", "application/json");
            FormBodyPart bodyPart2 = FormBodyPartBuilder.create()
                    .setBody(new StringBody(body, ContentType.TEXT_PLAIN))
            bodyPart2.addField("Content-type", "text/plain");
            HttpEntity entity = MultipartEntityBuilder

            String response = processHttpResp(httpClient, httpPost);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
Photo of Maritza Rico

Maritza Rico

  • 70 Points

Posted 3 years ago

  • 1
Photo of John Wang

John Wang, Official Rep

  • 5,826 Points 5k badge 2x thumb
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:!#RefCreateFaxMessage

faxing files:
Photo of VB

VB, Official Rep

  • 1,510 Points 1k badge 2x thumb
Please have a look at this code..  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