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