<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic AttachmentManager.search() Issues with attachment_where parameter in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/attachmentmanager-search-issues-with-attachment/m-p/1586914#M11164</link>
    <description>&lt;P&gt;Hi all, I'm experiencing issues using the search function from the AttachmentManager class. Currently I'm doing something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;item = gis.content.get(item_id)
fl = item.layers[0]

result = fl.attachments.search(where="1=1", attachment_where="ATT_NAME LIKE '%foto2_241023075432%'")

print(f"Attachments found: {len(result)}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I perform this query like this, the result is all&amp;nbsp; 31684 attachments, so the attachment_where parameter is being ignored.&lt;BR /&gt;&lt;BR /&gt;I performed the same query using the REST API, and it correctly returns the single attachment that matches my criteria.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Raul_0-1739973335188.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/125765i133C65920D898DC7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Raul_0-1739973335188.png" alt="Raul_0-1739973335188.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My organization is using ArcGIS Enterprise 11.3, and I myself am using the gis api for python 2.4.0 (the one that comes preinstalled with arcgis pro. Currently using ArcGIS Pro 3.4.0)&lt;/P&gt;</description>
    <pubDate>Wed, 19 Feb 2025 13:59:52 GMT</pubDate>
    <dc:creator>Raul</dc:creator>
    <dc:date>2025-02-19T13:59:52Z</dc:date>
    <item>
      <title>AttachmentManager.search() Issues with attachment_where parameter</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/attachmentmanager-search-issues-with-attachment/m-p/1586914#M11164</link>
      <description>&lt;P&gt;Hi all, I'm experiencing issues using the search function from the AttachmentManager class. Currently I'm doing something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;item = gis.content.get(item_id)
fl = item.layers[0]

result = fl.attachments.search(where="1=1", attachment_where="ATT_NAME LIKE '%foto2_241023075432%'")

print(f"Attachments found: {len(result)}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I perform this query like this, the result is all&amp;nbsp; 31684 attachments, so the attachment_where parameter is being ignored.&lt;BR /&gt;&lt;BR /&gt;I performed the same query using the REST API, and it correctly returns the single attachment that matches my criteria.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Raul_0-1739973335188.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/125765i133C65920D898DC7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Raul_0-1739973335188.png" alt="Raul_0-1739973335188.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My organization is using ArcGIS Enterprise 11.3, and I myself am using the gis api for python 2.4.0 (the one that comes preinstalled with arcgis pro. Currently using ArcGIS Pro 3.4.0)&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 13:59:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/attachmentmanager-search-issues-with-attachment/m-p/1586914#M11164</guid>
      <dc:creator>Raul</dc:creator>
      <dc:date>2025-02-19T13:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: AttachmentManager.search() Issues with attachment_where parameter</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/attachmentmanager-search-issues-with-attachment/m-p/1588031#M11175</link>
      <description>&lt;P&gt;For anyone having a similar issue, I created this function that uses the REST API to perform the query. I'm still using my instance of FeatureLayer and GIS objects :^]&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def __query_attachments_workaround(self, featurelayer, where=None, attachment_where=None):
	"""
	Performs the QueryAttachments operation using the GIS REST API
	Parameters:
		featurelayer (object): Instance of arcgis.features FeatureLayer class where to query attachments
		where (string | None): String representing the definition expression to be applied to FEATURES when performing query
		attachment_where (string | None): String representing the definition expressionm to be applied to ATTACHMENTS when performing query
	Returns:
		response_list (list): List of objects representing the server response to queryAttachments operation.
		The response has been formatted so it's similar to the native featurelayer.attachments.search() response
	"""
	import requests
	import json
	import sys
	try:
		url = f"{featurelayer.url}/queryAttachments"
		token = self.gis._con.token

		params = {
			'definitionExpression': where if where else "1=1",
			'attachmentsDefinitionExpression': attachment_where if attachment_where else '1=1',
			'f': 'json',
			'token': token
		}

		response = requests.post(url, params=params)
		if(response.status_code != 200):
			raise requests.RequestException('Invalid Server Reponse')

		response = json.loads(response.content)['attachmentGroups']
		response_list = []
		for record in response:
			response_list += [{
				'PARENTOBJECTID': record['parentObjectId'],
				'PARENTGLOBALID': record['parentGlobalId'],
				'ID': x['id'],
				'ATTACHMENTID': x['ATTACHMENTID'],
				'GLOBALID': x['GLOBALID'],
				'NAME': x['ATT_NAME'],
				'CONTENTTYPE': x['CONTENT_TYPE'],
				'SIZE': x['DATA_SIZE'],
				'DOWNLOAD_URL': f"{featurelayer.url}/{record['parentObjectId']}/attachments/{x['ATTACHMENTID']}?token={token}"
			} for x in record['attachmentInfos']]
		return response_list

	except Exception as e:
		print('An unhandled exception has occurred while querying for attachment infos')
		print(f"Details: {repr(e)}")
		sys.exit(5)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: this function currently belongs to a class that contains an instance to my GIS object, modify the code accordingly if you're going to use it in your environment.&lt;BR /&gt;&lt;BR /&gt;Hope the issue in the API gets solved soon tho!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 16:03:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/attachmentmanager-search-issues-with-attachment/m-p/1588031#M11175</guid>
      <dc:creator>Raul</dc:creator>
      <dc:date>2025-02-21T16:03:43Z</dc:date>
    </item>
  </channel>
</rss>

