Unable to add attachment to an Incident through External API whereas it works in postman with the direct servicenow attachment API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 06:35 AM
Created an EXternal API with Basic Auth to upload attachment to an incident through my python code, same headers and body works when i tried to hit the direct Servicenow attachment API via postman but when i try the same from python code it doesnt work.
Case 1 works but Case 2 doesn't
Case 1: Tried the Direct Service now attachment via Postman and it works
API https://instance.now.com/api/now/attachment/upload
Header :
Accept:application/json
Content-Type:multipart/form-data
Body:
table_name: incident
table_sys_id
uploadFile:
Case 2 : Created an External API which inturn will call the same servicenow upload attachment API and i am passing the header in the code whereas body in the run time via postman. trying to hit this api gets me the below error
Python Code:
response = requests.post(attach_url, data=request.get_data(), headers=attachheaders, verify=False)
Error
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 06:49 AM
https://community.servicenow.com/community?id=community_question&sys_id=2f9a072ddb5cdbc01dcaf3231f961987
This post should help, btw, have you tried testing it out using the REST API Explorer in SN.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 06:57 AM
Thank you for responding. Case 1 works whereas Case 2 doesnt work
Case 1: Tried the same via Postman and it works
API https://instance.now.com/api/now/attachment/upload
Header :
Accept:application/json
Content-Type:multipart/form-data
Body:
table_name: incident
table_sys_id
uploadFile:
Case 2 : Created an External API which inturn will call the same servicenow upload attachment API and i am passing the header in the code whereas body in the run time via postman. trying to hit this api gets me the below error
Python Code:
response = requests.post(attach_url, data=request.get_data(), headers=attachheaders, verify=False)
Error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 07:12 AM
try it from the SN REST API explorer and if it works, SN will provide the python code...