How to use an API key

This topic outlines the high-level steps of how to create and use API keys.

The API key workflow
The typical API key workflow

1. Create API key credentials

API key authentication requires a set of API key credentials.

The steps to create API key credentials with an ArcGIS Location Platform account are:

  1. Sign in to your ArcGIS portal.

  2. Click Content > My content > New item and select Developer credentials.

  3. In the Credential types menu, select API key credentials.

  4. Set the credential privileges to determine the operations your access token will be authorized to perform.

  5. Set the credential item access privileges to determine the items your access token will be authorized to access.

  6. Review your selections and, when you are ready, click Generate token. Save the access token as you will not be able to view it again.

2. Copy the API key

The API key credentials created in the previous step can contain up to two API keys. These long-lived access tokens are only visible once when they are created and are not stored anywhere in ArcGIS. Copy the API key to use it in your client application.

You can get the API key access token in two ways:

Get the access token immediately:

  1. 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 is created:

  1. Go to the item page of your API key credentials and click Credentials > Manage.

  2. Under API keys, click Regenerate API key to generate a new API key. This will invalidate the existing key.

  3. Alternatively, click Generate a secondary API key to generate a second API key without invalidating the first. The two keys share identical privileges, and each has a unique expiration date.

3. Use the API key

The last step is to use the API key access token to make requests to secure resources. To use the access token, embed it directly into your application.

ArcGIS REST APIs

This example shows how to access the geocoding service directly by setting the token parameter to an API key. To run this request, replace <YOUR_ACCESS_TOKEN> with an API key that has privileges to access the geocoding service.

cURLcURLHTTP
Use dark colors for code blocksCopy
1
2
3
4
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 with an ArcGIS API, the API key value is typically set once when the application is initialized and is applied every time a service request is made.

The examples below show how to use an API key to access the basemap styles service.

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for KotlinArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for QtArcGIS API for PythonEsri LeafletMapLibre GL JSOpenLayers
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      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.

Esri LeafletEsri LeafletMapLibre GL JSOpenLayersCesiumJS
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
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.


Migrate API keys (legacy) to API key credentials

Migrate from an API key (legacy) created before June 2024 to an API key from API key credentials.


Rotate API keys

Rotate API keys in a deployed application to refresh their expiration dates.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.