API keys (legacy) are permanent access tokens created before June 2024. They can no longer be created or managed, and have been replaced by API key credentials. All developers should replace their existing API keys (legacy) with new API keys from API key credentials.
This tutorial shows how to migrate your application from an API key (legacy) to an API key from API key credentials and preserve the same privileges and item access.
Prerequisites
-
You need an ArcGIS Location Platform account, ArcGIS Online account, or an ArcGIS Enterprise account. Additionally, ArcGIS Online and ArcGIS Enterprise accounts must have the correct user type and role. Please review the Product and account requirements before proceeding.
-
You need to know the privileges to assign to your API key. The privileges assigned allow your application to access specific ArcGIS services and resources.
Steps
Sign in to your portal
Check the scopes of your API key (legacy)
API keys (legacy) can only be scoped to access location services. These capabilities and more are available through API key credentials. Use your portal to check the service scopes of your API key (legacy) to create a new set of credentials with equivalent capabilities.
- Go to Content > My content.
- Click on the API key (legacy) item you want to replace. The item should have the label API key (legacy). You will then be redirected to the item page of your API key (legacy) item.
- Under Credentials, click Manage.
- In API key (legacy), scroll down to the Location services section.
- Write down the selected scopes under Required service and Available services. These scopes will be replicated in your API key credentials using privileges.
Create API key credentials
-
In your portal, click Content > My content > New item.
-
Click Developer credentials > API key credentials and click Next.
Need troubleshooting help?
If the Developer credentials option is not visible when creating a new item, your ArcGIS Online account does not have the correct permissions. You need an ArcGIS account with a user type of Creator or higher. Learn more about user types in the ArcGIS Online documentation.
If the API key credentials option is not visible when creating developer credentials, your ArcGIS Online account does not have the correct permissions. You need an ArcGIS account with a user type of Creator or higher. Your account must also have these additional privileges:
- General privileges > Content > Generate API keys
- General privileges > Content > Assign privileges to OAuth 2.0 applications
Your organization administrator can grant you these privileges using a custom role. To learn how, go to the ArcGIS Online documentation.
Set the expiration date and referrers
API key credentials generate long-lived access tokens called API keys. API keys are valid for up to one year, and their expiration date is set when they are generated. You can also set referrers on an API key, which restrict the key to only be usable from authorized domains.
-
In the Create developer credentials window, click on the Expiration date field. Set the expiration date of the access token to one month from today's date.
-
Set the Referrers field to the web domains you would like to restrict the access token to. This is highly recommended for security purposes. To learn more about referrers, go to API key credentials.
-
Click Next.
Select privileges
You can configure the settings of API key credentials to configure the privileges of access tokens. For an access token to work in your application, it needs to have the correct privileges to access the content and services your app is using. Select privileges for your API key credentials that mimic the scopes of your original API key (legacy).
-
In the Create developer credentials > Privileges window, browse the available privileges.
-
Expand the tables below to view the equivalent privileges for each location service scope of API keys (legacy).
API key (Legacy) scope Equivalent privilege Privilege string Basemaps Basemap styles service premium
:user :basemaps Geocoding (stored) Geocode (stored) premium
:user :geocode :stored Geocoding (not stored) Geocode (not stored) premium
:user :geocode :temporary Routing Simple routing premium
:user :networkanalysis :routing Optimized routing Optimized routing premium
:user :networkanalysis :optimizedrouting Closest facility Closest facility premium
:user :networkanalysis :closestfacility Service area Service area premium
:user :networkanalysis :servicearea Location allocation Location allocation premium
:user :networkanalysis :locationallocation Multi-vehicle routing Multi-vehicle routing premium
:user :networkanalysis :vehiclerouting Origin/destination cost matrix Origin/destination cost matrix premium
:user :networkanalysis :origindestinationcostmatrix Places Places service premium
:user :places GeoEnrichment GeoEnrichment service premium
:user :geoenrichment -
Select the location service privileges that mimic the original service scopes of your API key (legacy) and click Next.
Need troubleshooting help?
If the Privileges window is not visible when creating API key credentials, your ArcGIS Online account does not have the correct permissions. You need an ArcGIS account with a user type of Creator or higher. Your account must also have these additional privileges:
- General privileges > Content > Generate API keys
- General privileges > Content > Assign privileges to OAuth 2.0 applications
Your organization administrator can grant you these privileges using a custom role. To learn how, go to the ArcGIS Online documentation.
If you don't see a specific privilege in the Privileges window, there are several possible reasons:
- Certain location services are only available for ArcGIS Location Platform. Check the privileges available for your product type in Security and authentication > Privileges.
- If you have an ArcGIS Location Platform account, you need to enable pay-as-you-go in the Billing section of your dashboard to access some services, such as the GeoEnrichment service.
- If you have an ArcGIS Online account, your account may not have the correct role to access the services you need. Contact your organization administrator.
Select items (optional)
If your application will require access to specific private items, you will need to configure your developer credentials to access them. The Item access menu allows you to browse your portal's content and grant your API key access to specific items.
-
If your token does not require item access, click Skip.
-
Otherwise, in the Grant item access window, click Browse items.
-
Select the items you want to grant access to. You can select up to 100 items in this menu.
-
Click Add items.
Save the item
After configuring the properties of your API key credentials, you can save the credentials as a new item.
-
In the Create developer credentials window, set the following properties:
- Title:
My AP
I key credentials - Folder:
Developer credentials
(Create a new folder) - Tags: Add tags related to the privileges of the credentials.
- Description: Describe the application that these developer credentials will be used in.
Click Next.
- Title:
-
In the Summary window, review the properties, privileges, and item access you have set. If you selected any privileges with a personal scope, you must acknowledge the security implications before moving forward.
-
Click Next.
Copy the API key
-
In the Create developer credentials > Generate API key window, select Generate the API key and go to item details page. I am ready to copy and save the key.
-
Click Next.
-
Copy the API key from the window that appears and paste it into your application.
Delete the API key (legacy)
Once you replace your API key (legacy) in your application with your new API key, you can safely delete the API key (legacy) item.
- Go to Content > My content.
- Click on the API key (legacy) item you want to delete. You will then be redirected to the item page of your API key (legacy) item.
- Click on the Settings tab.
- In General, click Delete Item > Delete.
What's next?
Learn how to use your API key to access secure ArcGIS resources in the following guides: