Learn how to create an API key credential to get an access token.
To access ArcGIS services and resources with an access token, you need to configure the privileges for an API key credential in your portal. In your portal, you can also restrict referrer URLs and to set the expiration date for your credential.
In this tutorial, you will create an API key credential to get an access token to use in your application.
Prerequisites
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
You need to know the services and content that you want to access in your application.
Steps
Create an API key credential
You need to create an API key credential in your portal to generate an access token that you can use in requests to ArcGIS services. The privileges you set for the credential determine the capabilities of the token.
The expiration date and referrer URLs to restrict how long the access token can be used and the domain where it can be used.
-
Sign in to your portal.
- ArcGIS Location Platform: Go to https://location.arcgis.com and sign in. In the dashboard, click My portal to go to your portal.
- ArcGIS Online: Go to https://arcgis.com and sign in.
-
In your portal, click Content > My content > New item.
-
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 to one month from today's date.
-
Set the Referrers field to include only the web domains you would like your access token to be used from.
-
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
Your access token needs to have the correct privileges to access the content and services in your app. If you are following another ArcGIS tutorial, please refer to it to see the list of required privileges.
-
In the 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
The Item access menu allows you to browse your portal's content and grant your access token to specific private items.
-
If your access 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.
Copy the access token
After configuring the properties of your API key credential, you can save it as a new item and generate an access token.
-
In the Create developer credentials window, set the following properties:
- Title:
My AP
I key credential - Folder:
Developer credentials
(Create a new folder)
Click Next.
- Title:
-
In the Summary window, review the properties, privileges, and item access you have set. Then, click Next.
-
To get your access token, select Generate the API key and go to item details page. I am ready to copy and save the key.
-
Click Next.
-
Copy the access token from the window that appears and store it in a safe location.
Now you have an API key credential and access token that allows your application to access ArcGIS services and content.