- URL:
- https://<root>/<serviceName>/FeatureServer/<layerId>/queryAttachments
- Methods:
GET
- Version Introduced:
- 10.5
Description
The query
operation is performed on a feature service layer resource. The result of this operation are attachments grouped by the source feature object Ids and global ids (if exist).
Queries must include one of the following parameters: object
, global
, or definition
. All other parameters are optional and are used to further refine the returned results.
You can provide arguments to the Query Attachments operation as query parameters defined in the following parameters table:
New at 10.9.1
This operation supports a return
parameter for hosted feature services that returns the count of attachments per feature. The return
parameter is supported when the supports
property is set to true
(found under advanced
).
New at 10.8.1
- Field names are now returned in addition to the field properties in the
query
operation response. If the field name and property name match, including case, only one value is returned in the response to represent both field and property. As a best practice, it is best to go by the fieldname rather than the property when consuming this in an application.Attachments - When using the
attachments
parameter, you can use theDefinition Expression field
property from the layer'sName attachment
object. This describes the names of the fields that can be used in the expression. The layer'sProperties attachment
object lists more information about these fields, including type, which can be useful when building queries. This information is not provided in the layer resource at earlier releases, but the same field names can be used in those as well.Fields
Request parameters
Parameter | Details |
---|---|
(Required) | The object IDs of this layer/table to be queried. This parameter is not designed to be used in conjunction with the Syntax
Example
|
(Required) | The global IDs of this layer/table to be queried. This parameter is required if neither Syntax
Example
|
(Required) | The definition expression to be applied to the layer. Only those records that conform to this expression will be returned. This parameter is required if neither Example
|
| The definition expression to be applied to the attachments table. Only those records that conform to this expression will be returned. You can get the attachments table field names to use in the expression by checking the layer's Examples
|
| The attachment types to return. The following attachment types are supported for ArcGIS Online and ArcGIS Enterprise: Values: At this time, the following attachment types are supported in ArcGIS Online only: Values: Example
|
| The file size of the attachment is specified in bytes. You can enter a file size range (1000,15000) to query for attachments with the specified range. Example
|
| This parameter is designed to be used in conjunction with Example resultOffset setting
|
| This option fetches query results up to the Example
|
| Specifies whether to return the attachment URL. The default is Values: |
| If Values: |
| Returns attachments that match the keywords provided. The value provided for this parameter must be an exact match to the attachment's keyword value. This parameter can be set when the layer's Example
|
| New at 10.9.1. Specifies whether to return just the count of attachments per feature or row. Only returns results for features matching the query criteria that have a non-zero number of attachments. The default value is Values: |
| The response format. The default response format is Values: |
Example usage
Example one
The example below demonstrates how to query attachments using the parent objects
. The query results will return only the specified object ids.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2,4&globalIds=&definitionExpression=&attachmentTypes=&resultOffset=&resultRecordCount=&f=pjson
Example two
The example below demonstrates how to query attachments using the parent global
. The query results will returns only the specified global ids.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=&globalIds=60e35c5a-6bc5-4d52-a6db-b39bf566f7b9,e1f9d927-8fc9-4995-a2f6-373c9600d017&definitionExpression=&attachmentTypes=&size=&resultOffset=&resultRecordCount=&f=pjson
Example three
The example below demonstrates how to query attachments using the definition
as objectid>
and attachment
as impage
/jpeg. The query results will return all image/jpeg attachment types where the object id is greater than 2.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=&globalIds=&definitionExpression=objectid>2&attachmentTypes=image/jpeg&size=&resultOffset=&resultRecordCount=&f=html
Example four
The example below demonstrates how to query attachments using the definition
STATE_
as 'alaska'
, result
as 5, and result
as 10. The query results will skip the first 5 records and return the next 10 attachments in Alaska.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=STATE_NAME = 'alaska'&attachmentTypes=&size=&resultOffset=5&resultRecordCount=10&f=html
Example five
The example below demonstrates how to query attachments using the attachments
ATT_
as 'alaska_
and size
as 900,7000
. The query results will return all attachments within the specified file size range with the attachment name 'alaska.geodatabase'
.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=ATT_NAME = 'alaska.geodatabase'&attachmentTypes=&size=900,7000&resultOffset=&resultRecordCount=&f=html
Example six
The example below demonstrates how to query attachments using the definition
STATE_
as 'alaska'
, size
as 900,7000
, and return
as true
. The query results will return all attachments, including URLs, within the specified file size range in Alaska.
https://machine.domain.com/webadaptor/rest/services/light-inventory/FeatureServer/0/queryAttachments?objectIds=2&globalIds=&definitionExpression=STATE_NAME = 'alaska'&attachmentTypes=&size=900,7000&resultOffset=&resultRecordCount=&returnUrl=true&f=html
Example seven
The example below demonstrates how to query attachments using the definitionExpression as 1=1 and keywords as 'motorcycle'. The query results will return all attachment types that have a keywords value of motorcycle.
https://machine.domain.com/webadaptor/rest/services/Hosted/volcano_roop/FeatureServer/0/queryAttachments?definitionExpression=1%3D1&keywords=motorcycle&f=json
JSON Response syntax
{
"fields": [
{
"name": "OBJECTID",
"type": "<esriFieldTypeInteger>",
"alias": "<OBJECTID>",
"sqlType": "<sqlTypeOther>",
"domain": null,
"defaultValue": null
},
{
"name": "<GlobalID>",
"type": "<esriFieldTypeGlobalID>",
"alias": "<GlobalID>",
"sqlType": "<sqlTypeOther>",
"length": 38,
"domain": null,
"defaultValue": null
}
],
"attachmentGroups": [
{
"parentObjectId": "<OBJECTID>",
"parentGlobalId": "<esriFieldTypeGlobalID>",
"attachmentInfos": [
{
"id": "<OBJECTID>",
"globalId": "<esriFieldTypeGlobalID>",
"name": "<name>",
"contentType": "<attachmentTypes>",
"size": "<size>",
"url": "<returnUrl>"
}
]
}
]
}
JSON Response example
Example one
The example below demonstrates a response that is returned when the layer's attachment
contains field
properties.
{
"fields": [
{
"name": "objectid_1",
"type": "esriFieldTypeOID",
"alias": "OBJECTID_1",
"domain": null,
"defaultValue": null
},
{
"name": "globalid",
"type": "esriFieldTypeGlobalID",
"alias": "globalid",
"domain": null,
"defaultValue": null
}
],
"attachmentGroups": [
{
"parentObjectId": 2,
"parentGlobalId": "{F62F4A99-FACB-459D-8E29-7A1044EE2065}",
"attachmentInfos": [
{
"id": 1204,
"attachmentid": 1204,
"globalId": "{058333D1-D96C-4C19-A787-553FF119FD53}",
"globalid": "{058333D1-D96C-4C19-A787-553FF119FD53}",
"name": "red.png",
"att_name": "red.png",
"contentType": "image/png",
"content_type": "image/png",
"size": 381,
"data_size": 381
}
]
}
]
}
Example two
The example below demonstrates a query
response when return
is true
. In the response below, the feature with parent
that has two attachments, while the feature with parent
has five attachments.
{
"fields": [
{
"name": "OBJECTID_1",
"type": "esriFieldTypeOID",
"alias": "OBJECTID_1",
"sqlType": "sqlTypeOther",
"domain": null,
"defaultValue": null
},
{
"name": "GLOBALID",
"type": "esriFieldTypeGlobalID",
"alias": "GLOBALID",
"sqlType": "sqlTypeOther",
"length": 38,
"domain": null,
"defaultValue": null
}
],
"attachmentGroups": [
{
"parentObjectId": 25,
"parentGlobalId": "477711fe-461d-4fde-9aab-17cf3d38ad4f",
"count": 2
},
{
"parentObjectId": 21,
"parentGlobalId": "6066fb7d-e7b1-44de-9465-63a3df05bb59",
"count": 5
}
]
}