<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to programmatically check API key expiration in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-check-api-key-expiration/m-p/1575036#M11051</link>
    <description>&lt;P&gt;I'd like to write a Python script to run periodically and check the expiration date of my API keys, then email me about any that are expiring soon.&amp;nbsp; Currently, I can't figure out how to accomplish this with the ArcGIS Python API.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I tried using gis.api_keys.keys, but that only shows the old (deprecated) API keys&lt;/LI&gt;&lt;LI&gt;Then I tried gis.content.search("type:application"), which successfully fetches the new API key (developer credentials) items, plus all other application items.&amp;nbsp; It looked like the property "apiToken1ExpirationDate" would be the place to get the expiration dates, but it only returns the correct expiration date occasionally. Most of the time, it returns -1 instead.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is there another way to get the expiration date for developer credential API keys?&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2025 20:02:07 GMT</pubDate>
    <dc:creator>jdyerLACSD</dc:creator>
    <dc:date>2025-01-13T20:02:07Z</dc:date>
    <item>
      <title>How to programmatically check API key expiration</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-check-api-key-expiration/m-p/1575036#M11051</link>
      <description>&lt;P&gt;I'd like to write a Python script to run periodically and check the expiration date of my API keys, then email me about any that are expiring soon.&amp;nbsp; Currently, I can't figure out how to accomplish this with the ArcGIS Python API.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I tried using gis.api_keys.keys, but that only shows the old (deprecated) API keys&lt;/LI&gt;&lt;LI&gt;Then I tried gis.content.search("type:application"), which successfully fetches the new API key (developer credentials) items, plus all other application items.&amp;nbsp; It looked like the property "apiToken1ExpirationDate" would be the place to get the expiration dates, but it only returns the correct expiration date occasionally. Most of the time, it returns -1 instead.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is there another way to get the expiration date for developer credential API keys?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 20:02:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-check-api-key-expiration/m-p/1575036#M11051</guid>
      <dc:creator>jdyerLACSD</dc:creator>
      <dc:date>2025-01-13T20:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically check API key expiration</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-check-api-key-expiration/m-p/1698792#M11929</link>
      <description>&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;I do think the "apiToken1ExpirationDate" and "apiToken2ExpirationDate" properties are what you want, but it does look like you need to check if the token is valid first using the &lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/registered-app-info/" target="_self"&gt;"registeredAppInfo" endpoint&lt;/A&gt;, using the "apiToken1Active" and "apiToken2Active" properties. Putting that all together into a simple Python script would look like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from datetime import datetime
gis = GIS("home")
item = gis.content.get("API_KEY_ITEM_ID")
print(f"slot 1 expiration: {datetime.fromtimestamp(item.apiToken1ExpirationDate/1000).strftime('%B %d %Y at %I:%M.%S %p') if item.app_info.get("apiToken1Active") else 'None'}")
print(f"slot 2 expiration: {datetime.fromtimestamp(item.apiToken2ExpirationDate/1000).strftime('%B %d %Y at %I:%M.%S %p') if item.app_info.get("apiToken2Active") else 'None'}")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Apr 2026 17:22:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-check-api-key-expiration/m-p/1698792#M11929</guid>
      <dc:creator>GavinRehkemper</dc:creator>
      <dc:date>2026-04-28T17:22:27Z</dc:date>
    </item>
  </channel>
</rss>

