How to set Form-data in Rest Message ( attaching a file )

nagendra1891
Kilo Contributor

Hey guys,

I have everything set up and running the only issue is how to set the request of the rest message to ( -F ) form-data

My curl look like this.

curl https:/<endpoint url>/content \
  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \
  -F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
  -F file=@myfile.jpg

this is what causing the problem !!!   the body of the request must be set to -F ( form data )

-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
  -F file=@myfile.jpg

setContent() did not work

Screen Shot 2016-05-13 at 10.36.15 AM.png.

Any help is appreciated!!

regards

Nagendra

22 REPLIES 22

The backslashes in the request body look suspicious.



postFile.setRequestBody('attributes=\'{"name":"tigers.jpeg", "parent":{"id\":"##########"}}');



Have you tried building this out in the REST API explorer?



Getting Started with REST - ServiceNow Wiki


REST API Explorer - ServiceNow Wiki


REST API  


I Have the same issue .



When I am request the third Party Api through PostMan with "application/x-www-form-urlencoded" as a "Content-Type"   in header


and passing data as a key and the value of xml data under "x-www-form-urlencoded" tab, by this I am getting proper response.



find_real_file.png



But when I was trying to post the request through RESTMessageV2 in ServiceNow for outbound request , didn't get the response.


getting "![CDATA[No XML was posted to sdk listener]]"   as a response.



sm = new sn_ws.RESTMessageV2();


sm.setEndpoint('https://###################/listen.asp');


sm.setHttpMethod('post');


sm.setRequestHeader("Content-Type","x-www-form-urlencoded");


sm.setRequestBody("XML BODY");



Snippet from the ServiceNow Log..


find_real_file.png



Any suggestion on this really appreciated..



Thanks and Regards,


Subrata


I had the same issue, got to know that sometimes the third party queue has to be cleared , so i told my third party admin to clear it and it worked. I hope this helps .



Regards,
Shivalkar


ag101
Kilo Explorer

Even I have same query , did you solve it?


me too, anyone know



bueller