AnsweredAssumed Answered

When I upload multiple kmz files to AGOL as kml it doesn't generate a service URL

Question asked by vonmoosa Champion on Aug 31, 2020

When I run the script below to upload thousands of kmz files to my AGOL as kml they upload without a service url in item details. If I login to my account an use the add item tool to upload the files individual then a service url is generated. Any ideas?

import os
from arcgis.gis import GIS

path = r'PATH' # the folder where the .kml and .kmz files are stored

# List all .kml and .kmz files in the folder
KMLs = []

for root, dirs, files in os.walk(path):
    for file in files:
        if '.kml' in file or '.kmz' in file:
            KMLs.append(os.path.join(root, file))           

for KML in KMLs:

gis = GIS("", "USERNAME", "PASSWORD", verify_cert=False)

# Add the .kml and .kmz files
Items = []

for KML in KMLs:
    kml_properties = {
        'type': 'KML',
        'typeKeywords': os.path.split(KML)[1]

    data_file_location = KML
    # Add item to portal
    add_KML = gis.content.add(item_properties = kml_properties, data = data_file_location)
    # Share item to everyone
    add_KML.share(everyone = True)


for item in Items:

    print(item.title + ": " + "" +