AnsweredAssumed Answered

Programmatically download xml metadata files from ArcGIS Online

Question asked by jamie.leitch@welland.ca on Oct 15, 2020

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

Outcomes