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
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:
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.
- JavaScript SDK: https://github.com/ringcentral/ringcentral-js#fax
- PHP SDK: https://github.com/ringcentral/ringcentral-php
- Python SDK: https://github.com/ringcentral/ringcentral-python/
http://ringcentral-sdk-ruby.readthedocs.org/en/latest/usage/messages/Fax-Messages/#http-request-exam...
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