Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of multipart request for custom greeting #75

Open
cbzink opened this issue Aug 21, 2018 · 5 comments
Open

Example of multipart request for custom greeting #75

cbzink opened this issue Aug 21, 2018 · 5 comments

Comments

@cbzink
Copy link

cbzink commented Aug 21, 2018

I'm attempting to create a custom greeting as outlined in the docs: https://developer.ringcentral.com/api-docs/latest/index.html#!#RefCreateUserCustomGreeting. Unfortunately this is failing using both a WAV and MP3 file with a 415 Unsupported Media Type error. Below is an example of my code:

$multipartRequest = $rcsdk->createMultipartBuilder()->setBody([
    'type' => 'Voicemail',
    'answeringRule' => [
        'id' => '[redacted]'
    ],
])->add(fopen('test_greeting.mp3', 'r'))->request('/restapi/v1.0/account/~/extension/[redacted]/greeting');

$response = $rcsdk->platform()->sendRequest($multipartRequest);

Could you provide a working example of createMultipartBuilder for this use case? Thanks!

@cbzink
Copy link
Author

cbzink commented Aug 21, 2018

The following CURL request works perfectly fine with my MP3 file, so the functionality is clearly there and the API endpoint works leading me to believe it's definitely an issue with the PHP lib itself.

curl -i -X POST -H "Content-Type: multipart/mixed" -H "Authorization: Bearer [redacted]" -F "json={'type': 'Voicemail', 'answeringRule': {'id': '[redacted]'}};type=application/json" -F "binary=@test_greeting.mp3" https://platform.devtest.ringcentral.com/restapi/v1.0/account/\~/extension/[redacted]/greeting

@tylerlong
Copy link
Contributor

I don't think it is possible with this SDK. Becuase the SDK only supports multipart/form-data:

$headers = array('Content-Type' => 'multipart/form-data; boundary=' . $stream->getBoundary());

multipart/mixed is required in order to update custom greeting audio.

@vyshakhbabji What do you think?

@kirill-konshin
Copy link
Contributor

You can send any custom request if you assemble it manually.

@tylerlong
Copy link
Contributor

@kirill-konshin Yes I agree. Currently user has to do it the hard way.

And making updating greeting audio support multipart/form-data is in our backlog.

@grokify
Copy link
Contributor

grokify commented Aug 29, 2018

So for @cbzink's original question:

Could you provide a working example of createMultipartBuilder for this use case?

The situation is that createMultipartBuilder cannot be used due to incompatible MIME type, however, per @kirill-konshin, the request could be built manually:

You can send any custom request if you assemble it manually.

Can we provide an example of how to do this manually or a pointer to a multipart/mixed library to do this?

I did some Google searches and found CkMime but it is a commercial library:

https://www.example-code.com/phpExt/mime_multipartMixed.asp

I also found an unsuccessful reference to using Swift Mailer. At the time, multipart/mixed wasn't possible with v3 and waiting for v4 was recommended. They are on v6 now so it could be viable:

http://www.devnetwork.net/viewtopic.php?f=52&t=82799
https://swiftmailer.symfony.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants