News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
sandbox fax send: 400 "Bad Request"
Tags: errors, developer sandbox
Feb 5, 2016 at 5:41pm   •   4 replies  •  0 likes
bpe-inc

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  


4 Answers
answered on Jun 29, 2019 at 12:28pm  

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


 0
answered on Feb 5, 2016 at 10:23pm  
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.

 0
answered on Feb 5, 2016 at 9:20pm  
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.

 1
answered on Feb 5, 2016 at 9:13pm  
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...

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us