An API key is a long term access token that you manually create, configure, and scope using the developer dashboard. Using API keys is typically the easiest way to access ArcGIS location services in your applications.
To use API keys, you need to have one of the following accounts:
- ArcGIS Developer account
- ArcGIS Online account
How to use an API key
You can use the developer dashboard to create and manage API keys to access location services. API keys can be scoped. Make sure you have properly scoped your key in order to access the service(s) or content item(s) required in your application.
This is the typical workflow for using an API key in your application:
- Determine the API key scope required for the application.
- Create and scope an API key using your dashboard. To create a key, go to the Create an API key tutorial.
- Use the API key in your code where authentication is required.
Example
Use an API key to geocode an address
In this example, you use an API key, which is scoped to access geocoding service, to search for an address.
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_API_KEY") // API key scoped to access the geocoding service
});