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

Chuck Tomasi
Tera Patron

Hi Nagendra,



Is your main objective to create a file attachment? If so, the endpoint should end with /attachment/upload if you are using the Attachment API from our REST API. My CURL command looked more like this:



curl "https://instance.service-now.com/api/now/attachment/upload" \


--request POST \


--header "Accept:application/json"


--user 'admin':'admin'"\


--header "Content-Type:multipart/form-data"


-F 'table_name=incident' -F 'table_sys_id=12345678' -F 'encryption_context=undefined'-F 'uploadFile=@ location of the file on file system'



This was constructed using the REST API explorer. At the bottom, there is a cURL link.


find_real_file.png



The attachment API became available in Geneva. Your screen shot is UI15 so it's hard to tell if that's Fuji or Geneva.


hey ,


this curl is defined by external 3rd party api.



curl https:/<endpoint url>/content \


  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \


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


  -F file=@myfile.jpg



i want to setup outbound rest message .


how do i set request body to -F( form data )




regards


Nagendra


H Nagendra,



Just so I'm clear, you want to set up the outbound rest message in ServiceNow to send information to your 3rd party app, or the other way around (3rd party app posting information to ServiceNow?)


i want to set up the outbound rest message in ServiceNow to send information to your 3rd party app.