# arcgis-api > Always wrap API calls in try/except and provide meaningful error messages: - Author: Jeff Franzen - Repository: franzenjb/claude-skills - Version: 20260206183911 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-07 - Source: https://github.com/franzenjb/claude-skills - Web: https://mule.run/skillshub/@@franzenjb/claude-skills~arcgis-api:20260206183911 --- # ArcGIS API Patterns ## When to Use Automatically activate when the user is writing Python code that interacts with ArcGIS Online, ArcGIS Enterprise, or any ESRI service. This includes authentication, content management, sharing, administration, and any use of the `arcgis` Python package. ## Authentication Priority Order 1. **ArcGIS Notebooks**: Always use `GIS("home")` — no credentials needed 2. **OAuth (interactive apps)**: `GIS(url, client_id="APP_ID")` — safest for web apps 3. **API Key**: `GIS(api_key="AAPK...")` — public content only, no editing 4. **Username/Password**: `GIS(url, os.environ["USER"], os.environ["PASS"])` — scripts only **CRITICAL**: Never hardcode credentials. Always use environment variables. Always remind the user to add `.env` to `.gitignore`. ## Content Management Patterns ```python # Search for items items = gis.content.search("title:shelters AND type:Feature Service", max_items=50) # Get a specific item item = gis.content.get("ITEM_ID_HERE") # Update item properties item.update(item_properties={"title": "New Title", "tags": "updated,tags"}) # Share with organization item.share(org=True) # Share with specific group item.share(groups=["GROUP_ID"]) # Move to folder gis.content.create_folder("Projects") item.move("Projects") ``` ## Publishing Workflows ```python # CSV → Feature Layer csv_item = gis.content.add({"title": "My Data", "type": "CSV"}, data="path/to/file.csv") published = csv_item.publish() # GeoJSON → Feature Layer geojson_item = gis.content.add({"title": "Boundaries", "type": "GeoJson"}, data="path/to/file.geojson") published = geojson_item.publish() # DataFrame → Feature Layer from arcgis.features import GeoAccessor sdf = pd.DataFrame(...) # with SHAPE column or lat/lon sdf.spatial.to_featurelayer("Layer Name", gis=gis, folder="Projects") ``` ## Error Handling Always wrap API calls in try/except and provide meaningful error messages: ```python try: result = fl.edit_features(adds=features) failures = [r for r in result['addResults'] if not r['success']] if failures: print(f"Warning: {len(failures)} records failed to add") except Exception as e: print(f"Error: {e}") if "Token Required" in str(e): print("Authentication issue — check your credentials") elif "exceeded" in str(e).lower(): print("Rate limit or credit limit — try smaller batches") ```