question

automation-usa avatar image
automation-usa asked ·

Switching to -F/--form option for posting multipart/mixed forms?

My front-end development framework's cURL implementation requires all curl options be entered as raw text strings (text/plain). This is causing me all sorts of headaches with such things as posting multipart/mixed forms (i.e. FaxOut API requests).

For example, this works perfectly for me in Shell terminal but not in my front-end environment:
curl -X POST "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax"; --header "Content-Type: multipart/mixed; boundary=Boundary_1_14413901_1361871080888" --header "Accept: application/json" --header "Authorization: Bearer {
                 {access_token}}" -d "--Boundary_1_14413901_1361871080888
Content-Type: application/json
{
  \"to\":[{\"phoneNumber\":\"18005630003\"}],
  \"faxResolution\":\"High\",
  \"sendTime\":\"2013-02-26T09:31:20.882Z\"
}
--Boundary_1_14413901_1361871080888
Content-Type: text/plain
Hello, World!
--Boundary_1_14413901_1361871080888--"
When I try the same command from my front-end I get:
{  "message" : "Bad Request",
  "errors" : [ ]
}
The  cURL http scripting docs recommend using "--form" commands for RFC1867 posting. If correct, can you provide some working examples for Faxing and MMS of how boundaries and content-types would be specified when using "-F" options?

P.S. Any other solution or workaround would be welcomed.









topic-default
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

ak avatar image
ak answered ·
You could use the -F option to add each section of the multipart that you would want to POST. I did find something which might be helpful :
https://ec.haxx.se/http-multipart.html

Let us know if this helps.

Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

automation-usa avatar image
automation-usa answered ·
Hi AK,

Thanks for your reply, your multipart form posts curl reference was somewhat helpful in that it moved me on to a different error response :|

So, I reconstructed my request as follows:
curl -X POST https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax"  --header "Accept: application/json"   --header "Authorization: Bearer {
                 {my access token}}"   -F to=18005630003   --header "Content-Type: text/plain"   -F coverIndex=12  --header "Content-Type: text/plain"   -F faxResolution=High   --header "Content-Type: text/plain"   -F attachment=Hello, World!  --header "Content-Type: text/plain" 
I did this in attempt to mimic the " Pattern 3 Request format: multipart/form-data" example in your API Reference. And now the response to my request is always:
{
                 
  "message" : "Unsupported Media Type",
  "errors" : [ ]
}
Tried different kinds of syntax and adding/removing options. Still nothing.
1 comment Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Could you try the below :

curl -i -X POST https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax" 
--header "Accept: application/json"  
--header "Authorization: Bearer { {my access token}}"
--header "Content-Type: multipart/mixed"
-F file=filename.txt"
-F body={\"to\":[{\"phoneNumber\":\"18005630003\"}],\"faxResolution\":\"High\,\"sendTime\":\"2013-02-26T09:31:20.882Z\};type=application/json"
0 Likes 0 · ·
automation-usa avatar image
automation-usa answered ·
Hi AK,

I tried your code. Got yet another (different) error response:
{    "errorCode" : "InvalidContent",    "message" : "Unable to parse fax envelope",    "errors" : [ {      "errorCode" : "MSG-349",      "message" : "Unable to parse fax envelope"    } ]  }

I tried the -F options with and without leading/trailing quotes. I even tried breaking out the "type=applicaton/json" into a trailing -H option (i.e. -H "Content-Type: application/json"). Same error.
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered ·
curl \
--header "Accept: application/json" \
--header "Authorization: Bearer <token>" \
-F "request=@request.json;type=application/json" \
-F "attachment=@hello.txt;type=text/plain" \
"https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax"

Content of request.json file:

{
                 
 "to": [{ "phoneNumber": <fax receiver> }]
}

Content of hello.txt:

<Whatever text you want to send.>

You can also send pdf:

-F "attachment=@test.pdf;type=application/pdf"
1 comment Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

That Works. Awesome Tyler. 


0 Likes 0 · ·
automation-usa avatar image
automation-usa answered ·
Thanks Tyler. That worked like a charm! :)

Now I gotta try something similar with MMS. Do you know when the MMS endpoint will be available for testing in the Sandbox?
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

automation-usa avatar image
automation-usa answered ·
Oops! Spoke to soon. Now my attachments are not rendering.

-----------------------------------------
" Your fax included the following file(s). Please check the file(s) that could not be rendered for errors or refer to our website for supported file types.

Name                                   Phone Number          Date and Time                      Result
                                            +1 (305) 4081720                                                  Failed

File Name                                                                                                         
Result
attachmentContent                                                                                            Not rendered"
-----------------------------------------

It's as if the attachment were being truncated or the Content-Length was not being calculated.

Even the text/plain example fails with just the phrase "Hello, world!" Just fyi, I am encoding the pdfs using Base64 (RFC 4648 )

This is the result of my post request:
{    "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/540887020/extension/540887020/message-store/765035724012",    "id" : 765035724012,    "to" : [ {      "phoneNumber" : "+13054081720",      "location" : "Miami, FL",      "messageStatus" : "Queued"    } ],    "type" : "Fax",    "creationTime" : "2017-03-30T21:46:29.000Z",    "readStatus" : "Unread",    "priority" : "Normal",    "attachments" : [ {      "id" : 765035724012,      "uri" : "https://media.ringcentral.com/restapi/v1.0/account/540887020/extension/540887020/message-store/765035724012/content/765035724012",      "type" : "RenderedDocument",      "contentType" : "application/pdf"    } ],    "direction" : "Outbound",    "availability" : "Alive",    "messageStatus" : "Queued",    "faxResolution" : "High",    "faxPageCount" : 0,    "lastModifiedTime" : "2017-03-30T21:46:29.833Z",    "coverIndex" : 12  }
And the response headers are:
HTTP/1.1 100 Continue    HTTP/1.1 200 OK  Server: nginx/1.10.2  Date: Thu, 30 Mar 2017 21:46:29 GMT  Content-Type: application/json; charset=UTF-8  Content-Length: 416  Connection: keep-alive  RCRequestId: 55130dfe-1592-11e7-a7ce-005056affef3  RoutingKey: SJC01P05PAS06  Content-Language: en-US  Vary: Accept-Encoding, User-Agent  Content-Encoding: gzip  X-Rate-Limit-Group: heavy  X-Rate-Limit-Limit: 20  X-Rate-Limit-Remaining: 19  X-Rate-Limit-Window: 60


Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered ·
I just tied sending a plain text file with "hello world" as content and succeeded.


Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered ·
Just fyi, I am encoding the pdfs using Base64 (RFC 4648 )

Please don't encode it with Base64. Just send it as binary.

Please reply if you still cannot get it work.
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered ·
Just sent a PDF file successfully using curl:


Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

automation-usa avatar image
automation-usa answered ·
Hi Tyler,

Thanks for following up. I appreciate your assistance.

For security reasons, my development framework does not permit direct file access, therefore I cannot simply point a variable to a binary. I have to load the binary into a variable and then I can make curl requests with it. My choices for that are either Hex Encoding or Base64 Encoding.

Having said, I'd like to test a couple of debugging exercises:
  1. I will test sending a fax cover sheet with a fax cover message and no attachment. If a fax can go thru with no attachment, then the binary is the issue.
  2. I'm gonna set up "mock bin" to capture my request and see what's coming across to you when I post an attachment (text or pdf)
Hopefully I'll be able to figure out what's going on with my fax form, as I will need similar code for posting an MMS form.
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.