Attachment API
-
- UpdatedAug 3, 2023
- 12 minutes to read
- Vancouver
- API reference
The Attachment API provides endpoints that allow you to upload and query file attachments.
You can upload or retrieve a single file with each request.
The Attachment API respects any system limitations on uploaded files, such as maximum file size and allowed attachment types. You can control these settings using the properties com.glide.attachment.max_size, 1024MB by default, and glide.attachment.extensions.
The following video provides more information on the Attachment API:
Attachment API role requirements
To create attachments, the user record used to authenticate the HTTP request with ServiceNow must have any roles required to create Attachment [sys_attachment] records. It must also have any roles required to read and write records on the target table, such as the itil role to add attachments to incident records.
By default there is no single role allowing a user to add attachments. You can create a role to explicitly allow adding attachments, then assign this role to the user account being used to make the request.
Attachment - DELETE /now/attachment/{sys_id}
This method deletes the attachment with a specific sys_id value.
URL format
Versioned URL: /api/now/v1/attachment/{sys_id}
Default URL: /api/now/attachment/{sys_id}
Supported request parameters
Name | Description |
---|---|
sys_id | Sys_id value of the attachment to delete. Data type: String |
Name | Description |
---|---|
None |
Name | Description |
---|---|
None |
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.
Header | Description |
---|---|
None |
Header | Description |
---|---|
None |
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 API HTTP response codes.
Response body parameters (JSON or XML)
Name | Description |
---|---|
None |
Example: cURL request
Attachment - GET /now/attachment
Returns the metadata for multiple attachments.
URL format
Versioned URL: api/now/v1/attachment
Default URL: api/now/attachment
Supported request parameters
Name | Description |
---|---|
None |
Name | Description |
---|---|
sysparm_limit | Limit to be applied on pagination. Note: Unusually large sysparm_limit values can impact system performance.Data type: String Default: 1000 |
sysparm_offset | Number of records to exclude from the query. Use this parameter 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.Data type: String Default: 0 |
sysparm_query | 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,
Data type: String |
Name | Description |
---|---|
None |
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.
Header | Description |
---|---|
Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
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 API HTTP response codes.
Status code | Description |
---|---|
200 | Successful. The request was successfully processed. |
401 | Unauthorized. The user credentials are incorrect or haven't been passed. |
500 | Internal server error. An unexpected error occurred while processing the request. The response contains additional information about the error. |
Response body parameters (JSON or XML)
Name | Description |
---|---|
Returned information depends on the selected attachments. |
Example: cURL request
Attachment - GET /now/attachment/{sys_id}/file
Returns the binary file attachment with a specific sys_id value.
URL format
Versioned URL: /api/now/v1/attachment/{sys_id}/file
Default URL: /api/now/attachment/{sys_id}/file
Supported request parameters
Name | Description |
---|---|
sys_id | Sys_id of the attachment record from which to return binary data. |
Name | Description |
---|---|
None |
Name | Description |
---|---|
None |
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.
Header | Description |
---|---|
Accept | Data format of the response body. For example, use image/jpeg
or image/png to accept JPEG or PNG image files exclusively. To
allow all image types, specify image/* ; to allow any file type,
specify */* .Default: */* |
Header | Description |
---|---|
X-Attachment-Metadata | Metadata about the returned file, such as size, name, and file type. |
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 API HTTP response codes.
Response body parameters (JSON or XML)
Name | Description |
---|---|
Binary file attachment |
Example: cURL request
Attachment - GET /now/attachment/{sys_id}
Returns the metadata for the attachment file with a specific sys_id value.
URL format
Versioned URL: /api/now/v1/attachment/{sys_id}
Default URL: /api/now/attachment/{sys_id}
Supported request parameters
Name | Description |
---|---|
sys_id | Sys_id of the attachment record for which to retrieve the metadata. |
Name | Description |
---|---|
None |
Name | Description |
---|---|
None |
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.
Header | Description |
---|---|
Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
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. |
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 API HTTP response codes.
Response body parameters (JSON or XML)
Name | Description |
---|---|
Metadata specific to the specified attachment. |
Example: cURL request
Attachment - POST /now/attachment/file
Uploads a specified binary file as an attachment to a specified record.
URL format
Versioned URL: /api/now/v1/attachment/file
Default URL: /api/now/attachment/file
Supported request parameters
Name | Description |
---|---|
None |
Name | Description |
---|---|
<String> | Path to the binary file to attach to the specified record. |
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.
Header | Description |
---|---|
Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
Content-Type | Content type of the file to attach, such as image/jpeg or */*. This header is mandatory to post file attachments. |
Header | Description |
---|---|
Location | URL of the new attachment. |
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 API HTTP response codes.
Response body parameters (JSON or XML)
Example: cURL request
Attachment - POST /now/attachment/upload
Uploads a multipart file attachment.
The multipart POST method does not accept any parameters. You must specify the table name and record sys_id values within the form body. See the cURL example for a sample of a multipart/form-data request.
URL format
Versioned URL: /api/now/v1/attachment/upload
Default URL: /api/now/attachment/upload
Supported request parameters
Name | Description |
---|---|
None |
Name | Description |
---|---|
None |
Name | Description |
---|---|
None |
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.
Header | Description |
---|---|
Accept | Data format of the response
body. Supported types: application/json or
application/xml.
Default: application/json |
Content-Type | Content type of the request. Set this value to multipart/form-data when using the multipart POST method. |
Header | Description |
---|---|
Location | URL of the new attachment. |
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 API HTTP response codes.
Response body parameters (JSON or XML)
POST multipart mandatory values
Value | Description |
---|---|
Content-Type | Content-Type of the file, included in the message body for multipart
uploads. Note: The Content-Type must be defined within the file portion of the
POST message, not within the form data. See the sample POST multipart message
for an example of a multipart message.
Data type: String |
table_name | Name of the table to which you want to attach the file. Data type: String |
table_sys_id | Sys_id of the record on the specified table to which you want to attach the
file. Data type: String |