API key credentials

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:

  1. Sign in to your 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 privileges to determine the operations your token will be authorized to perform.

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

  6. Review your selections and, when you are ready, click Generate token or Go to item details.

  7. Copy the resulting access token and paste it somewhere safe. You will not be able to see it again.

  8. You can now use the access token to access services and data.

Example

Use an API key to geocode an address

In this example, you use an API key with privileges to access geocoding service to search for an address.

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
import { ApiKeyManager } from "@esri/arcgis-rest-request";
import { geocode } from "@esri/arcgis-rest-geocoding";

geocode({
  address: "1600 Pennsylvania Ave",
  postal: 20500,
  countryCode: "USA",
  authentication: ApiKeyManager.fromKey("YOUR_ACCESS_TOKEN") // API key scoped to access the geocoding service
});

Tutorials

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