Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

brian_
Tera Guru

Here's my fix. I see it would solve several of the questions in this thread.



find_real_file.png


Convert your key: value pair to a raw data format of key=value with an & inbetween value and the next key:


key=value&nextkey=nextvalue&thirdkey=thirdvalue


find_real_file.png



Then place this into the Content portion of your message


ALSO set a HTTP Header of:



Content-Type: application/x-www-form-urlencoded


find_real_file.png


Sandeep Kumar6
Giga Guru

Hi Nagendra,

 

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

 

Please hit like if this helped you.

 

regards

Sandeep

prabhatkuchibho
ServiceNow Employee

Hi, 

Multipart/form-data requests are now supported via the REST action step in the IntegrationHub which comes as part of the ServiceNow IntegrationHub Installer plugin available for a fee in the Madrid release.

The procedure to set this up is explained in the below knowledge article. 
How to send Outbound REST request with multipart/form-data

Regards,
Prabhat