Read attachments information
This example set demonstrates how to use the get_attachments endpoint.
This endpoint retrieves attachment metadata directly from the ServiceNow sys_attachment table, allowing fast server-side filtering on attachment-level attributes. Use it when you want to query attachments across a table without first filtering parent records. For parent-level filtering (slower per-parent processing), use the Get Attachments By Parent Row Search endpoint instead.
Use the Query parameter for server-side filters on the sys_attachment table (examples: file_nameENDSWITH.png, content_typeSTARTSWITHimage/, size_bytes>1048576, or date placeholders like <<today-2d,FUN_TO_DATETIME>>). You can also specify a ParentSysId to limit to a single parent record or use SysId for a specific attachment. Replace sample sys_id and table names with values from your instance.
-- Get all attachments for the parent table 'problem'
SELECT * FROM get_attachments WITH(TableName='problem')
-- Get attachments where file name ends with .png or .zip (attachment table filter)
SELECT * FROM get_attachments WITH(TableName='problem', Query='file_nameENDSWITH.png^ORfile_nameENDSWITH.zip')
-- Get all attachments for a specific parent record (by parent sys_id)
SELECT * FROM get_attachments WITH(TableName='problem', ParentSysId='62304320731823002728660c4cf6a7e8')
-- Get a single attachment metadata row by exact attachment sys_id
SELECT * FROM get_attachments WITH(SysId='4b2d41168396b21032ddb9f6feaad38f')
-- Get attachments uploaded today
SELECT * FROM get_attachments WITH(TableName='problem', Query='sys_created_on>=<<today,FUN_TO_DATETIME>>^sys_created_on<=<<today|~|yyyy-MM-dd 23:59:59,FUN_TO_DATETIME>>')
-- Get attachments uploaded in the last 2 days
SELECT * FROM get_attachments WITH(TableName='problem', Query='sys_created_on>=<<today-2d,FUN_TO_DATETIME>>')
-- Get attachments uploaded after a specific date
SELECT * FROM get_attachments WITH(TableName='problem', Query='sys_created_on>=2026-01-01')
-- Get attachments with exact file name match
SELECT * FROM get_attachments WITH(TableName='problem', Query='file_name=dump.png')
-- Get attachments where file name starts with 'dump'
SELECT * FROM get_attachments WITH(TableName='problem', Query='file_nameSTARTSWITHdump')
-- Get attachments where file name contains 'error'
SELECT * FROM get_attachments WITH(TableName='problem', Query='file_nameLIKEerror')
-- Get attachments where file name ends with .pdf
SELECT * FROM get_attachments WITH(TableName='problem', Query='file_nameENDSWITH.pdf')
-- Get only image attachments
SELECT * FROM get_attachments WITH(TableName='problem', Query='content_typeSTARTSWITHimage/')
-- Get attachments larger than 1 MB
SELECT * FROM get_attachments WITH(TableName='problem', Query='size_bytes>1048576')
-- Get attachments uploaded by a specific user
SELECT * FROM get_attachments WITH(TableName='problem', Query='sys_created_by=admin')
-- Order attachments by created date (ascending)
SELECT * FROM get_attachments WITH(TableName='problem', Query='ORDERBYsys_created_on')
-- Order attachments by size descending
SELECT * FROM get_attachments WITH(TableName='problem', Query='ORDERBYDESCsize_bytes')