Learn how to create an API key using API key credentials.
An API key is a long-lived access token that authorizes your application to access secure services, content, and functionality in ArcGIS. API keys are generated using API key credentials, a type of item you create and manage in your portal. API key credentials contain settings that allow you to generate API keys and manage properties such as their privileges and expiration date.
This tutorial shows you how to use your portal to create API key credentials to do the following:
-
Generate long-lived API keys and save them in your application.
-
Configure properties of API key credentials, such as expiration date and referrer URLs.
-
Configure privileges to allow your API keys to access ArcGIS services, content, and functionality.
Prerequisites
-
You need an ArcGIS Location Platform or ArcGIS Online account to create an API key to access location services. Your account must have a user type of Creator or higher and the correct permissions to generate API keys. To learn more, go to Security and authentication > Product and account requirements.
-
You need to know the services and content that you want to access in your application.
Steps
Create an API key credential
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 your portal, click Content > My content > New item.
-
Click Developer credentials > API key credentials and click Next.
-
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.
-
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.
Still need help? Go to the Security and authentication guide.
Select location services privileges
For an API key to work in your application, it needs to have the correct privileges to access the content and services your app is using. If you are following another ArcGIS tutorial, please refer to it to see the list of required privileges.
-
In the Create developer credentials > Privileges window, browse the available privileges.
-
Select the privileges required by your application 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.
Still need help? Go to the Security and authentication guide.
Grant item access
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 API key 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.
Copy the API key
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. Then, click Next.
-
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.
This is the only time you will be able to access the value of your API key. You will not be able to view it again. To get a new key, you need to regenerate one using the API key credentials item page.
Now you have an API key that allows your application to access ArcGIS services and content.