Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Downloading file from ServiceNow using Rest API

DKS
Kilo Explorer

Hi,

First of all, I have gone through the documentation on Attachment API. I am able to get the repsonse from the API and also the Binary response(as mentioned in the doc) for the attachment. I dont quite understand how to decode this reponse and create back the original file that is there as attachment in SN.

Actually I have created a script in python and my response has characters like this - ��]�������VX�M��꥟�����2I

The same I am getting from postman as well. Please help how can I create a actual file from this.

Thanks

6 REPLIES 6

Thanks for sharing the code.

Unfortunately this is not working for me. It may be due to any restriction that I have in my workplace. This produces error as "socket.gaierror: [Errno 11001] getaddrinfo failed"

I have followed the documentation here if you could share the relevant code that would be a great help.

My code:

headers={Authorization: Token_no, Accept":"*/*}

r=requests.get(Api_endpoint/attachment/sys_id/file,headers)

data=r.content

"Data produces the content something like this h�b```"V �� Ȁ �L@Q� �@���`6��b�c�6Lv��9.... how to decode and create back the actual file from this content?

 

Thanks

Try to recreate this in a PDI.

Share only teh code that actually downloads the file content so someone who knows python can reproduce the issue.

Sorry I'm not able to get you to a resolution here.