Hello All,
Is there an ArcGIS API for Python method to update feature layer attachments? The documentation shows add and delete, but not update: ArcGIS API for Python | Layer Attachments
I am looking to update attachment keywords programmatically. I was able to accomplish this by using the REST API (lines 35-37 in code sample below), but would rather use the API for Python. Surely I am just missing how to update in the docs?
## Example script to update attachment keywords for records in a hosted feature layer
## Arthur Smith 3/31/2026
# Import necessary modules
from arcgis.gis import GIS
import requests
# Log in to AGOL via ArcGIS for Python
gis = GIS("home")
# Set variables
row_permit_item_id = "*********************" # DEV ROW Permit feature layer
new_keyword = 'Current Permit PDF' # Desired value to update keyword with
# Get session token value to use in REST API call
token_val = gis.session.auth.token
row_permit_lyr = gis.content.get(row_permit_item_id).layers[0] # Get the permit layer FeatureLayer
query = "1=1" # Query to specify which records to analyze
row_permit_featureset = row_permit_lyr.query(where=query).features # Get the permit layer FeatureSet
# Loop through each feature in the permit featureSet and analyze attachments
for f in row_permit_featureset:
cur_oid = f.as_dict["attributes"]["objectid"]
cur_permit_id = f.as_dict["attributes"]["permit_id_txt"]
print("Permit record " + cur_permit_id)
cur_attachments = row_permit_lyr.attachments.get_list(oid=cur_oid) # Get all attachments for current feature
print("Has " + str(len(cur_attachments)) + " attachments")
for a in cur_attachments: # Loop through each attachment
if cur_permit_id in a["name"] and "Permit PDF" not in a["keywords"]: # Check if any attachments exist with permit ID in their name, and permit pdf not in keywords
print("POSSIBLE PERMIT PDF WITHOUT KEYWORD FOUND")
print(a["name"])
print("Keyword tags: " + a["keywords"])
print("updating ...")
update_url = row_permit_lyr.url + "/" + str(cur_oid) + "/updateAttachment?token=" + token_val # Construct AGOL REST API call URL to update the current attachment
payload = {'attachmentId': str(a["id"]), 'keywords': new_keyword, 'f': 'json'} # Construct the payload for API call
response = requests.request("POST", update_url, headers={}, data=payload, files=[]) # Make the attachment keyword update API call
print(response.text)
print("-----")