简体   繁体   English

请求 RingCentral API

[英]Request to RingCentral API

I am trying to send a request to RingCentral API .我正在尝试向RingCentral API发送请求。 The link to documentation is https://developers.ringcentral.com/api-reference/Fax/createFaxMessage If I don't specify faxResolution or coverIndex everything goes well, fax could be sent.文档链接是https://developers.ringcentral.com/api-reference/Fax/createFaxMessage如果我没有指定faxResolutioncoverIndex一切顺利,可以发送传真。 But if I add faxResolution param like in the code below, I receive error "Parameter [faxResolution] value is invalid", "errorCode": "CMN-101".但是如果我像下面的代码一样添加faxResolution 参数,我会收到error "Parameter [faxResolution] value is invalid", "errorCode": "CMN-101". The same thing with coverIndex param.与coverIndex 参数相同。 My client is GuzzleHttp 6.3我的客户是GuzzleHttp 6.3

    $token = $this->ringcentral->platform()->auth()->data()['access_token'];
    $a = array();
    foreach ($destination_numbers as $number) {
        $a[] = [
            'name' => 'to',
            'contents' =>  $number,
            'headers' => ['Content-Type' => 'multipart/form-data']
        ];
    }
    $a[] = [
            'name' => 'faxResolution',
            'contents' => 'High',
            'headers' => ['Content-Type' => 'multipart/form-data']
        ];
    foreach ($attachments as $attachment) {
        $file_pointer = fopen($attachment, 'r');
        $mime = mime_content_type($attachment);
        $a[] = [
            'name' => 'attachment',
            'contents' => $file_pointer,
            'headers' => ['Content-Type' => $mime]
        ];
    }
    $client = new Client();
    try {
        $response = $client->request('POST', url(config('services.ringcentral.app_url')) . '/restapi/v1.0/account/~/extension/~/fax', [
            'headers' => [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer ' . $token
            ],
            'multipart' => $a
        ]);
        $response = json_decode($response->getBody(), true);
    } catch (\GuzzleHttp\Exception\ClientException $e) {
        echo($e->getResponse()->getBody()->getContents());
    }

Here's what RingCentral suggests when using PHP.以下是 RingCentral 在使用 PHP 时的建议。 I included all of what they suggested, but just look at the part about faxResolution (2/3 of the way down)我包括了他们建议的所有内容,但只看一下关于faxResolution 的部分(向下的2/3)

    <?php
// https://developers.ringcentral.com/my-account.html#/applications
// Find your credentials at the above url, set them as environment variables, or enter them below

// PATH PARAMETERS
$accountId = '<ENTER VALUE>';
$extensionId = '<ENTER VALUE>';

$recipient = '<ENTER VALUE>';

require('vendor/autoload.php');
$rcsdk = new RingCentral\SDK\SDK(getenv('clientId'), getenv('clientSecret'), getenv('serverURL'));
$platform = $rcsdk->platform();
$platform->login(getenv('username'), getenv('extension'), getenv('password'));

$request = $rcsdk->createMultipartBuilder()
    ->setBody(array(
     'to' => array(array('phoneNumber' => $recipient)),
     'faxResolution' => 'High',
    ))
    ->add(fopen('fax.jpg', 'r'))
    ->request("/restapi/v1.0/account/{$accountId}/extension/{$extensionId}/fax");

$r = $platform->sendRequest($request);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM