Attachment API - POST /now/attachment/file

sreeju
Kilo Explorer

Hello,

I am trying to build an application that collect a report from another application,create an incident and attach to it. I wrote this application in Python. When ever i tried to to attach a file using ecc_queue i am getting an error as below.

Response Status Code: 200

Response JSON Content: {u'reason': None, u'error': u'Insufficient rights to insert records from the table: ecc_queue'}

when i contacted the servicenow administrator he said that ecc_queue is not secure plus he wants me to provide the exact acl in the ecc_queue,we are using geneva implementation. Later he told me to try Attachment API - POST /now/attachment/file.

I have tried this as per the documentation and i get below error.

Response Status Code: 400

Response JSON Content: {u'status': u'failure', u'error': {u'message': u'Attachment is empty', u'detail': None}}

I also tried Attachment API - GET /now/attachment/{sys_id}/file to check if i can retrive an exsisting attachment ,but i dint work as well. i get below error message.

Response Status Code: 404

Response JSON Content: {u'status': u'failure', u'error': {u'message': u'No Record found', u'detail': u"Record doesn't exist or ACL restricts the record retrieval"}}

Please help me.

Thanks

Sree

1 ACCEPTED SOLUTION

santo544
Mega Contributor

Hi Sreejith,



Below code works perfectly fine in Fuji and Geneva, but there is a whole new Attachment API in Geneva as you mentioned,



POST Body


{


"agent":"AttachmentCreator",


"topic":"AttachmentCreator",


"name": "Issue_screenshot.jpg:application/jpg",


"source":"incident:Sys_ID",



"payload":"Base64_string_of_the_attachment"


}



I am currently exploring the Geneva API's


View solution in original post

24 REPLIES 24

Hello,


'incident:cc565618c0a80a6b00ff2a4d06a6b729' is incide a variable called "inc" and that variable is there in the payload section.


same as auth, i have passed basic authentication credentials inside the dictionary and pass that to python request post.



I have checked table name, and table name is just "attachment", because when i just removed the file_name i got below error that mean "attachment" is the right name. I also tried sys_attacment as you said but that not recoganize.



Response Status Code: 400


Response JSON Content: {u'status': u'failure', u'error': {u'message': u'Missing parameter: file_name', u'detail': None}}



I have checked with Admin he says that i have all the permissions.



If you look at the original error massage below , it says "attachment is empty" plus http error code is 400,that means something different in the http header,but i cant locate that.



Response Status Code: 400


Response JSON Content: {u'status': u'failure', u'error': {u'message': u'Attachment is empty', u'detail': None}}



Thanks
Sree


Hi Sree,



You may already know this, but just in case - Have you used the REST API Explorer to help build the proper URI, headers, payload, etc? I find it an excellent tool for building third party integrations.



REST API Explorer - ServiceNow Wiki


Let me take a look but i could attach the file inside an incident using ecc_queue in the development environment but my servicenow admin is saying he cant give me the same right in the production environment as it cause some security risk.He asked me to use api attachment option in Geneva, well,i think you are right the error i receive is http code 400, that means something missing in the http header field.



thanks


Sree


Check this out. They even have a Python code sample.



Attachment API


Attachment API - POST /now/attachment/file


Well, Thats the one i was trying,but i got the error i was saying