Skip to content

APIKeyManager.get() and .keys methods fail to retrieve existing API keys in ArcGIS Python API 2.4.0 #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pmd84 opened this issue Mar 11, 2025 · 0 comments
Labels

Comments

@pmd84
Copy link

pmd84 commented Mar 11, 2025

Describe the bug

The APIKeyManager.get() method and keys property don't correctly retrieve existing API keys, despite documentation suggesting these should return valid API keys. The API keys exist and can be found through content search, but the dedicated API key retrieval methods return None or empty lists.

To Reproduce

Steps to reproduce the behavior:

import arcgis
from arcgis.gis import GIS

# Connect to ArcGIS Online
gis = GIS("https://www.arcgis.com", "username", "password")

# First search for API keys to confirm they exist
api_keys = gis.content.search(query="", item_type="Application", 
                             max_items=10, 
                             outside_org=False)
api_key = [k for k in api_keys if "APIToken" in k.typeKeywords][0]
print(f"API Key found via content search: {api_key.title} (ID: {api_key.id})")

# Try to retrieve the same API key using documented methods
print("\nAttempting API Key retrieval using get() method")
key_by_title = gis.api_keys.get(title=api_key.title)
print(f"Result: {key_by_title}")  # Returns None

# Try using APIKeyManager directly
print("\nAttempting retrieval via APIKeyManager")
api_key_manager = arcgis.gis._impl.APIKeyManager(gis)
keys_list = api_key_manager.keys
print(f"API keys found: {len(keys_list)}")  # Returns 0 even when keys exist

Expected behavior

The get() method should return an API key when given a valid title, and the keys property should return a list of all available API keys for the authenticated user.

Workaround

The only working approach is to manually instantiate an APIKey class with an item found through content search:

# Workaround: create API key class directly
from arcgis.gis._impl import APIKey
api_key_class = APIKey(api_key, gis)
print(f"Successfully created API Key class via workaround: {api_key_class}")

Platform

  • OS: Databricks
  • Python API Version: 2.4.0

Additional context

The official documentation at https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#apikeymanager suggests these methods should work as expected, but they don't seem to function correctly in version 2.4.0.

@pmd84 pmd84 added the bug label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant