marystromberg
ServiceNow Employee
ServiceNow Employee

This video shows how to use the REST API to GET, POST, and DELETE attachments on the ServiceNow platform. It applies to ServiceNow releases starting with Geneva. You will need access to perform the desired attachment operation on the target record and table.

For best video quality, increase your player resolution to 1080p.

This video covers:

For more information on REST Attachment API, see ServiceNow product documentation: REST Attachment API.

Your feedback helps us better serve you! Did you find this video helpful? Leave us a comment to tell us why or why not.

Comments
Jeet
Tera Expert

Hi Mary Stromberg,



Thank you for providing such kind of helpful video



I have one requirement in web services....



If I have two attachment for same sys_id and I want to download specific one,


How can we achieve this.



Thanks,


Jeet


silas1
ServiceNow Employee
ServiceNow Employee

Hi Jeet,



If I understand your question correctly, I think you're asking about the scenario where you have multiple attachments for the same target record, and you're only interested in one of those attachments, is that right?  



You can use the "GET /api/now/v1/attachment" endpoint to get all attachment metadata for a given target record by specifying the target table and sys_id via an encoded query in sysparm_query:



In this example, the target table is "incident" and the sys_id of the target record is "85071a1347c12200e0ef563dbb9a71c1".


GET https://<instance>.service-now.com/api/now/v1/attachment?sysparm_query=table_name%3Dincident%5Etable_sys_id%3D85071a1347c12200e0ef563dbb9a71c1


This will give you back metadata for each attachment including a download link, so you can request the one you're interested in.



Hope this helps!


-Silas



(Sample of response):



{
  "result": [
  {
  "size_bytes": "8",
  "file_name": "file1.txt",
  "sys_mod_count": "0",
  "average_image_color": "",
  "image_width": "",
  "sys_updated_on": "2017-03-21 16:30:13",
  "sys_tags": "",
  "table_name": "incident",
  "sys_id": "07253e474fa172001f6eac118110c73a",
  "image_height": "",
  "sys_updated_by": "admin",
  "download_link": "https://<instance>.service-now.com/api/now/v1/attachment/07253e474fa172001f6eac118110c73a/file",
  "content_type": "text/plain",
  "sys_created_on": "2017-03-21 16:30:13",
  "size_compressed": "28",
  "compressed": "true",
  "table_sys_id": "85071a1347c12200e0ef563dbb9a71c1",
  "sys_created_by": "admin"
  },
  {
  "size_bytes": "8",
  "file_name": "file2.txt",
  "sys_mod_count": "0",
  "average_image_color": "",
  "image_width": "",
  "sys_updated_on": "2017-03-21 16:30:18",
  "sys_tags": "",
  "table_name": "incident",
  "sys_id": "9035ba474fa172001f6eac118110c7c3",
  "image_height": "",
  "sys_updated_by": "admin",
  "download_link": "https://<instance>.service-now.com/api/now/v1/attachment/9035ba474fa172001f6eac118110c7c3/file",
  "content_type": "text/plain",
  "sys_created_on": "2017-03-21 16:30:18",
  "size_compressed": "28",
  "compressed": "true",
  "table_sys_id": "85071a1347c12200e0ef563dbb9a71c1",
  "sys_created_by": "admin"
  }
  ]
}





Version history
Last update:
‎10-31-2016 09:49 AM
Updated by: