question

bpe-inc avatar image
bpe-inc asked ·

sandbox fax send: 400 "Bad Request"

Here is output from my script which shows how the python requests class is building my request. I've compared this to the examples online and I don't see what's wrong with it. I have stripped out the actual html content and modified the destination fax number to hide where it's really going.

submitting content type: multipart/form-data; boundary=6b4176ac3af14157b06702ace82f6ad3  submitting data: '''--6b4176ac3af14157b06702ace82f6ad3  Content-Disposition: form-data;  Content-Type: application/json    {"to": [{"phoneNumber": "+15555555555"}], "faxResolution": "High", "coverIndex": 0}  --6b4176ac3af14157b06702ace82f6ad3  Content-Disposition: form-data; name="file"; filename="T0000001.htm"  Content-Type: text/html    
(html is here)  
--6b4176ac3af14157b06702ace82f6ad3-- ''' url=' https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax' status code=400 content type=application/json;charset=UTF-8 encoding=UTF-8 text='{ "message" : "Bad Request", "errors" : [ ] }'Here is the code generating that output:

 def SubmitFax ( self, fax_destination_number, html_file_name, html_file_content ):    access_token = self.GetAccessToken()        j = {     "to": [{"phoneNumber": fax_destination_number}],     "coverIndex": 0,     "faxResolution": "High",    }    files = {     '': ('', json.dumps(j), 'application/json'),     'file': (html_file_name, html_file_content, 'text/html')    }    if True:     e = requests.models.RequestEncodingMixin     body,content_type = e._encode_files(files,None)     print("submitting content type: {}".format(content_type))     print("submitting data: '''{}'''".format(body))    if False:     log('{0}: submitting data \"\"\"{1}\"\"\"'.format(html_file_name, html_file_content))        headers = {     'User-Agent': self.user_agent,     'Authorization': 'Bearer {}'.format ( access_token )    }    url = '{self.url}/restapi/v1.0/account/~/extension/~/fax'.format ( **locals() )    print('url='{}''.format(url))    r = requests.post ( url, headers=headers, files=files )    if False:     example_error_response = """{    "message" : "Bad Request",    "errors" : [ ]  }'"""    #j = json.loads(r.text)    if True:     print('status code={}'.format(r.status_code))     print('content type={}'.format(r.headers.get('content-type')))     print('encoding={}'.format(r.encoding))     print("text='{}'".format(r.text))     return None  

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.

John Wang avatar image
John Wang answered ·
There may be issues with your fax MIME body. Compare your request to the ones in the following example page:

http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/messages/Fax-Messages/#http-request-exam...
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.

bpe-inc avatar image
bpe-inc answered ·
I found the problem. The example code I found online for changing the content type from multipart/mime to multipart/mixed had a bug that was clobbering the boundary tag.
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.

John Wang avatar image
John Wang answered ·
Glad to hear the problem is solved.

The PHP and JavaScript SDKs have fax helper libraries, but the Python SDK doesn't yet. If you're interested in creating a generic one, it may be worthwhile to send a pull request.
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.

Anirban Sen Chowdhary avatar image
Anirban Sen Chowdhary answered ·

The issue clearly shows the contentType... Since the fax api support attachments as data. 400 error is caused due to wrong content or mime type

Content-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#

Following reference has described the same:

https://forums.developers.ringcentral.com/questions/517/weird-boundary-in-presence-response-when-requestin.html

https://forums.developers.ringcentral.com/questions/614/switching-to-f-form-option-for-posting-multipartmi.html?page=2&pageSize=10&sort=oldest

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.