OutBound Rest Message with a attachment

nagendra1891
Kilo Contributor

Hey guys,

I need to send ServiceNow attachments from the business rule when a record is inserted

Use case :   if new incident with attachment is created,   business rule needs to grab the attachment and post it to 3rd party endpoint

endpoint looks like this

curl ########################### \
  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \
  -F attributes='{"name":"#######", "parent":{"id":"########"}}' \
  -F file=@myfile.jpg

can this be achieved with outbound rest message ?

any help is really appreciated

regards

NB

9 REPLIES 9

bernyalvarado
Mega Sage

Hi Nagendra,



I'll suggest you use the GlideSysAttachment API.



Thanks,


Berny



The following blog should also be helpful:



Reading Attachments Using ServiceNow GlideSysAttachment API



Thanks,


Berny


jarodm
Mega Guru

I have struggled with this for far too long (using GlideSysAttachment() and other methods) until I got the correct answer one day from josh.nerius in the SNDevs Slack channel...



Docs article: RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId)



This single line added to your scripted outbound REST message will download the attachment into your request body before sending it to the remote endpoint.



Enjoy!


The slack channel mentioned above is run by whom?


It's run by a group of active developers/architects (not officially run by SN Inc.). There are a bunch of very active members, and over 1700 total registered members.



Check out https://sndevs.com for an invite and join us.