Attach a file using rest api

sanjeev22
Kilo Explorer

Hi

I am trying to attach a file to service now request.

I followed below method to attach the file

Method   : https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/reference/...

URL :  

https://dev24647.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=e837e7b24f...

but getting below error , there must be something wrong how I specify the file name to attach Has any one encountered similar error or attached a file successfully.

i am getting below error

Curl output

===========

{"error":{"message":"Requested URI does not represent any resource","detail":"Requested URI does not represent any resou

rce Check logs for error trace or enable glide.rest.debug property to verify REST request processing"},"status":"failure

"}

Python script output

=================

('Status:', 400, 'Headers:', {'X-Cnection': 'close', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'JSESSIONID=B9AB8B6B0745ECDE3F736FB47CBAFCE5;Secure; Path=/; HttpOnly, BIGipServerpool_dev24647=3816850442.32576.0000; path=/', 'Strict-Transport-Security': 'max-age=15768000; includeSubDomains;', 'Server': 'ServiceNow', 'Date': 'Mon, 20 Jun 2016 18:26:24 GMT', 'Content-Type': 'application/json'}, 'Error Response:', {u'status': u'failure', u'error': {u'message': u'Requested URI does not represent any resource', u'detail': u'Requested URI does not represent any resource Check logs for error trace or enable glide.rest.debug property to verify REST request processing'}})

5 REPLIES 5

Nathan Grove
Kilo Expert

It doesn't look like their sample Python script has any data in the post body. Here is a quick link on how to use requests.post for python. It should have a data="some data here" as a parameter into the post function call.



Quickstart — Requests 2.10.0 documentation



If you are simply playing around with the file API, try to use the cURL example they give on the page you linked to.



Edit: On the cURL call I forgot to mention that you will need to add "\" at the end of each line (except for the last) in bash. They didn't include them on lines 4 and 5. I ran the curl without the last slashes and received a similar message as yours.


Dharshini Rohit
Tera Contributor

Hi Sanjeev,



Did you get around it? I am trying the same and seems like both the sample cURL and Python scripts dont work at all. I always get this error:


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



Does anyone know what value to pass to uploadFile? It seems like Servicenow is unable to retrieve my attachment.



Thanks in advance


Dharshini


Hi Dharshini,



Were you able to get around this, i am trying to upload an attachment using REST API in Geneva, and hit on the same error?


Hi Karthik,



Yes, apparently we should use setRequestBodyFromAttachment() function to send files.


Wiki article is not that clear. But the above function sends a base64 encoded file to the   endpoint.



Hope this helps