API key authentication requires a set of API key credentials. These credentials are used to generate long-lived access tokens and include settings that define their privileges and item access. You can manage the properties of API key credentials to define the privileges and expiration date associated with the access token, generate additional access tokens, and invalidate existing tokens. They are a type of developer credentials and are created in the Content management > New item menu.
API key credentials should not be mistaken with API keys (legacy). If you have an API key (legacy) created before June 2024, you need to migrate to the new API key credentials to get an access token with expanded privileges.
How to create API key credentials
The typical steps to create API key credentials are:
-
Sign in to your portal.
-
Click Content > My content > New item and select Developer credentials.
-
In the Credential types menu, select API key credentials.
-
Set the privileges to determine the operations your token will be authorized to perform.
-
Set the item access privileges to determine the items your token will be authorized to access.
-
Review your selections and, when you are ready, click Generate token or Go to item details.
-
Copy the resulting access token and paste it somewhere safe. You will not be able to see it again.
-
You can now use the access token to access services and data.
Example
Use an access token to display a basemap
const accessToken = "YOUR_ACCESS_TOKEN";
const basemapURL = "https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:Streets?type=style&token=";
olms(map, basemapURL + accessToken); // API key scoped to access the basemap styles service