Unable to add attachment to an Incident through External API whereas it works in postman with the direct servicenow attachment API

Jeya
Tera Contributor

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

 
{
    "error": {
        "message": "Failed to create the attachment. File part might be missing in the request.",
        "detail": null
    },
    "status": "failure"
}
 

 

3 REPLIES 3

Sukraj Raikhraj
Kilo Sage

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.

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

 
{
    "error": {
        "message": "Failed to create the attachment. File part might be missing in the request.",
        "detail": null
    },
    "status": "failure"
}

try it from the SN REST API explorer and if it works, SN will provide the python code...