-1

I am using RingCentral PHP SDK for sending request. I tried some methods, they were working. But when I try to send fax with $rcsdk->createMultipartBuilder() method, I get response "Bad request" message, nothing else specified.

This code return Bad Request:

    $request = $this->ringcentral->createMultipartBuilder()
            ->setBody(array(
                'to' => array(
                    array('phoneNumber' => '1267***0722')),
                'faxResolution' => 'High',
            ))
            ->add(fopen($file->path, 'r'))
            ->request("/account/~/extension/~/fax");

While this work fine and fax is sent

    $request = $this->ringcentral->createMultipartBuilder()
            ->setBody(array(
                'to' => array(
                    array('phoneNumber' => '1267***0722')),
                'faxResolution' => 'High',
            ))
            ->add('Plain Text', 'file.txt')
            ->request("/account/~/extension/~/fax");

Also I tried to send cURL, it also returns Bad Request

curl --request POST --url 'https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax' --header 'accept: application/json' --header 'authorization: Bearer '<mycode>' --header 'content-type: multipart/form-data' --data '{"attachment":"data:text/plain;name= test.txt;base64,VGVzdCBtZXNzYWdl","to":["1201***0654"]}'
Grokify
  • 15,092
  • 6
  • 60
  • 81
  • Well then I’d start by verifying what `fopen($file->path, 'r')` actually returned. – 04FS Nov 08 '19 at 14:06
  • $file->path is path on my server to this file. Function fopen($file->path, 'r') returns a file pointer. Its a PDF file – Sorokin_Dmitry Nov 08 '19 at 14:46

1 Answers1

0

Since the fax api support attachments as data. 400 error is caused due to wrong content or mime type: multipart/mixed

The API allows sending a fax message with a multipart request, incorporating two or more parts.

ref: https://developers.ringcentral.com/api-reference#

Have you checked this, the curl command included mime type as multipart/mixed:
https://forums.developers.ringcentral.com/questions/614/switching-to-f-form-option-for-posting-multipartmi.html?page=2&pageSize=10&sort=oldest

and this: https://forums.developers.ringcentral.com/questions/221/sandbox-fax-send-400-bad-request.html

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81