Get contents of attachment record using cURL?

mmcbride1007
Tera Contributor

Does anyone know of a way to get an attachment record from the system using cURL on the command line? We've tried a basic curl "http://myinstance.service-now.com/sys_attachment.do?sys_id=12345" and also adding user authentication, using curl -user "username:password" "https://myinstance.service-now.com/sys_attachment.do?sys_id=12345" with no luck. The REST API is no good in this situation since it returns a JSON object of the database record rather than the actual content of the attachment. We're trying to download a CSS file that we've attached to a UI page, so we need the actual CSS contained in the attachment.

Mark Stanger (Crossfuze) John Andersen hoping you guys may have stumbled across something like this or could point me where to look...

1 ACCEPTED SOLUTION

Hey! Yeah we did solve it. We ended up using a processor, which uses basic auth when they hit that URL. We passed the sys_id of the attachment record in as a parameter in the processor, and were able to get the contents of the attachment based on knowing the sys_id.


View solution in original post

5 REPLIES 5

NStefanisko
Tera Expert

We managed to get the attachment, in my case an image, without using a processor. I'm going to try to explain the process without code, since I don't know what language you are using. Hopefully not bash, this would be really hard in bash.



1) Figure out the attachment's sys_id, this can be found in the sys_attachment table along with all the other interesting bits of information about the attachment. In the example below I'm using sys_id=1234567890. I'm also using XML, but it looks like JSONv2 works too.


                  https://blah-blah.service-now.com/sys_attachment.do?XML&useUnloadFormat=true


2) Query the sys_attachment_doc table with the attachment's sys_id as sys_attachment


                    https://blah-blah.service-now.com/sys_attachment_doc.do?XML&sysparm_query=sys_attachment=1234567890


3) This gives you back an object with 4k chunks of base64 encoded data (other information too that is useful for reassembly, you'll understand when you see it)


4) Reassemble the parts by base64 decoding them and then concatenating them in the correct order, Hint: "position" means order


5) This gives you a gzip'ed version of your attachment, so un-gzip the data


6) Finally you have your actual binary data, save it to a file and use it.



Ta Da!