通过RingCentral API发送传真

时间:2019-11-08 14:00:58

标签: php curl ringcentral

我正在使用RingCentral PHP SDK发送请求。我尝试了一些方法,它们正在起作用。但是,当我尝试使用$rcsdk->createMultipartBuilder()方法发送传真时,收到响应“错误的请求”消息,未指定其他任何内容。

此代码返回错误请求:

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

虽然可以正常工作并且可以发送传真

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

我也尝试发送cURL,它还会返回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"]}'

1 个答案:

答案 0 :(得分:0)

因为传真api支持将附件作为数据。 400错误是由于内容或MIME类型错误而引起的:multipart/mixed

API允许发送包含多部分请求(包含两个或更多部分)的传真消息。

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

您是否已检查过,curl命令将mime type包含为multipart/mixed
https://forums.developers.ringcentral.com/questions/614/switching-to-f-form-option-for-posting-multipartmi.html?page=2&pageSize=10&sort=oldest

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

相关问题