This topic outlines the high-level steps of how to create and use API keys
1. Create API key credentials
API key authentication
2. Copy the API key
The API key credentials
You can get the API key access token in two ways:
Get the access token immediately:
- When you first create API key credentials, click Generate token to create an API key. Copy the resulting string.
Get the access token after the item
-
Go to the item page
An item page is a web page in ArcGIS Online or the developer dashboard used to access and manage the properties for an item and the content it references such as a web map, hosted layer, or file. of your API key credentialsAPI key credentials are an item that contains the parameters used to create and manage long-lived access tokens for API key authentication. They are a type of developer credential. and click Credentials > Manage. -
Under API keys, click Regenerate API key to generate a new API key
An API key is a long-lived access token created using API key credentials. They are valid for up to one year and are typically embedded directly into client applications. . This will invalidate the existing key. -
Alternatively, click Generate a secondary API key to generate a second API key without invalidating the first. The two keys share identical privileges
Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. , and each has a unique expiration date.
3. Use the API key
The last step is to use the API key access token
ArcGIS REST APIs
This example shows how to access the geocoding servicetoken parameter to an API key<YOUR with an API key that has privileges
curl https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates \
-d "f=pjson" \
-d "address=1600 Pennsylvania Ave NW, DC" \
-d "token=<YOUR_ACCESS_TOKEN>"ArcGIS APIs
If you use API key authentication
The examples below show how to use an API key to access the basemap styles service
esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
const map = new Map({
basemap: "arcgis/topographic", // Basemap layer
});
const view = new MapView({
map: map,
center: [-118.805, 34.027],
zoom: 13, // scale: 72223.819286
container: "viewDiv",
constraints: {
snapToZoom: false,
},
});
Open source APIs
If you are using an open source or third-party API, you can set the access using a class or property (if they are available), otherwise, you need to add a token parameter to each service request and include your access token.
The examples below show how to use an access token to access the basemap styles service
const apiKey = "YOUR_ACCESS_TOKEN";
const map = L.map('map', {
center: [34.027, -118.805]
});
map.setView([34.027, -118.805], 13); // latitude, longitude, zoom level, scale: 72223.819286
const basemapEnum = "arcgis/topographic"
L.esri.Vector.vectorBasemapLayer(basemapEnum, {
token: accessToken
}).addTo(map)Tutorials
Create an API key
Create and configure API key credentials to get a long-lived API key access token.
Manage API key credentials
Manage previously created API key credentials to regenerate, edit privileges, and edit item access of API keys.
Update to API key credentials
Migrate from an API key (legacy) created before June 2024 to an API key from API key credentials.