The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Any examples of a multipart/form-data posting attachment content using REST API

owainr
Kilo Explorer

Been struggling with this for ages, able to send the meta data using the POST <instance>/api/now/attachment/file but when using the POST <instance>/api/now/attachment/upload with the content of the file it always returns -

'{"error":{"message":"Failed to create the attachment. File part might be missing in the request.","detail":null},"status":"failure"}'

Tried an array of methods with the multipart in php and none of them seem to return anything other then this

Please help

TIA

5 REPLIES 5

santoshsahoonis
Kilo Guru

Rasmita
Tera Contributor

I am getting the same error.


bgworld
Giga Expert

I was able to post it using postman. check screenshots below:



Note: Don't supply content type in headers when using postman.



find_real_file.png


find_real_file.png



Note from stackoverflow post:


Beware, when testing your webservice using chrome postman, you need to check the form data option(radio button) and File menu from the dropdown box to send attachment. Explicit provision of content-type as multipart/form-data throws an error. Because boundary is missing as it overrides the curl request of post man to server with content-type by appending the boundary which works fine.


Link: html - What is the boundary in multipart/form-data? - Stack Overflow


Sandeep Kumar6
Giga Guru

Hi Owainr,

 

Its been confirmed by ServiceNow that they do not support content-type as "multipart/form-data"  .The only solution is either use Mid server or create own proxy server where you can send as Binary Stream .

 

There are others content-type as "Application/Json" which  you can use.

Just to keep in mid that ServiceNow sends Text data out of ServiceNow.

reference:

https://community.servicenow.com/community?id=community_question&sys_id=a8df36addb58dbc01dcaf3231f9619fb

https://community.servicenow.com/community?id=community_question&sys_id=c78487a9dbd8dbc01dcaf3231f96191d

  or You can take help from Here

 

https://docs.servicenow.com/integrate/inbound_rest/reference/r_SamplePOSTMultipart.html

 

Please hit like if this helped you.

 

regards

Sandeep