Attachment API - GET /now/attachment

This method gets the metadata for multiple attachments.

URL format

Versioned URL: api/now/v1/attachment

Default URL: api/now/attachment

Supported request parameters

Table 1. Parameters
Parameter Description
sysparm_query An encoded query. Queries for the Attachment API are relative to the Attachments [sys_attachment] table.

For example: (sysparm_query=file_name=attachment.doc)

The encoded query provides support for order by. To sort responses based on certain fields, use the ORDERBY and ORDERBYDESC clauses in sysparm_query. For example, sysparm_query=ORDERBYfile_name^ORDERBYDESCtable_Name orders the results in ascending order by name first, and then in descending order by table name.

If part of the query is invalid, such as by specifying an invalid field name, the instance ignores the invalid part. It then returns rows using only the valid portion of the query. You can control this behavior using the property glide.invalid_query.returns_no_rows. Set this property to true to return no rows on an invalid query.
Note: This property controls the behavior of all queries across the instance, such as in lists, scripts (GlideRecord.query()), and web service APIs.
sysparm_limit Limit to be applied on pagination. The default is 10000.

Unusually large sysparm_limit values can impact system performance.

sysparm_offset A number of records to exclude from the query. Use this parameter when you need to get more records than specified in sysparm_limit. For example, if sysparm_limit is set to 500, but there are additional records you want to query, you can specify a sysparm_offset value of 500 to get the second set of records.
sysparm_suppress_pagination_header Set this value to true to remove the Link header from the response. The Link header enables you to request additional pages of data when the number of records matching your query exceeds the query limit.

Headers

The following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see Supported REST API headers.

Table 2. Request headers
Header Description
Table 3. Response headers
Header Description
Content-Type The content type of the response. For metadata requests, this is the content type of the metadata, not the content type of the attachment files.
Link Links to download the attachments.

Status codes

The following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see REST response codes .

Table 4. Status codes
Status code Description
200 Indicates the query ran successfully.

Sample cURL request

curl "https://instance.service-now.com/api/now/attachment?sysparm_limit=1" \
--request GET \
--header "Accept:application/json" \
--user 'admin':'admin'
{
  "result": [
    {
      "table_sys_id": "5054b6f8c0a800060056addcf551ecf8",
      "size_bytes": "462",
      "download_link": "https://instance.service-now.com/api/now/attachment/615ea769c0a80166001cf5f2367302f5/file",
      "sys_updated_on": "2009-05-21 04:12:21",
      "sys_id": "615ea769c0a80166001cf5f2367302f5",
      "image_height": "",
      "sys_created_on": "2009-05-21 04:12:21",
      "file_name": "blocks.swf",
      "sys_created_by": "glide.maint",
      "compressed": "true",
      "average_image_color": "",
      "sys_updated_by": "glide.maint",
      "sys_tags": "",
      "table_name": "content_block_programmatic",
      "image_width": "",
      "sys_mod_count": "0",
      "content_type": "application/x-shockwave-flash",
      "size_compressed": "485"
    }
  ]
}

Sample Python request

#Need to install requests package for python
#easy_install requests
import requests

# Set the request parameters
url = 'https://instance.service-now.com/api/now/attachment?sysparm_limit=1'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'admin'
pwd = 'admin'

# Set proper headers
headers = {"Content-Type":"application/xml","Accept":"application/xml"}

# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers  )

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)
<?xml version="1.0" encoding="UTF-8"?>
<response>
   <result>
      <table_sys_id>5054b6f8c0a800060056addcf551ecf8</table_sys_id>
      <size_bytes>462</size_bytes>
      <download_link>https://instance.service-now.com/api/now/attachment/615ea769c0a80166001cf5f2367302f5/file</download_link>
      <sys_updated_on>2009-05-21 04:12:21</sys_updated_on>
      <sys_id>615ea769c0a80166001cf5f2367302f5</sys_id>
      <image_height />
      <sys_created_on>2009-05-21 04:12:21</sys_created_on>
      <file_name>blocks.swf</file_name>
      <sys_created_by>glide.maint</sys_created_by>
      <compressed>true</compressed>
      <average_image_color />
      <sys_updated_by>glide.maint</sys_updated_by>
      <sys_tags />
      <image_width />
      <table_name>content_block_programmatic</table_name>
      <sys_mod_count>0</sys_mod_count>
      <content_type>application/x-shockwave-flash</content_type>
      <size_compressed>485</size_compressed>
   </result>
</response>