Programmatically download xml metadata files from ArcGIS Online

932
1
10-15-2020 09:37 AM
Col_Forbin
New Contributor III

Can a python script in ArcMap be used to download the metadata.xml files for all items in my ArcGIS Online account into a local folder?  If anyone has done anything like this I'd really appreciate some help.  I can update the metadata.xml file using:

def update_metadata(user, item, token, metadata):
    
    d = {"overwrite": "true",
         "token" :token,
         "f":"json"}
    f = {'metadata': ('metadata.xml', open(metadata, 'rb'), 'text/xml', {'Expires': '0'})} 
    
    url = r'https://www.arcgis.com/sharing/rest/content/users/{0}/items/{1}/update'.format(user, item)
    r = requests.post(url, data = d, files = f)

    response = json.loads(r.content)

    if 'error' in response.keys():
        raise Exception(response['message'], response['details'])

    return response

thanks

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor

According to the API help file you can download metadata for an item, see here.

0 Kudos