Tutorial: Create an API key

Learn how to create and manage an API key using API key credentials.

API key credentials
The developer credentials creation interface in a portal

An API key is a long-lived access token that authorizes your application to access secure services, content, and functionality in ArcGIS. API keys are generated using API key credentials, a type of item hosted in your portal. API key credentials contain settings that allow you to generate API keys and manage properties such as their privileges and expiration date. The process of creating API key credentials and using an API key in your application is known as API key authentication.

This tutorial shows you how to create API key credentials and do the following:

  • Generate long-lived API keys and save them in your application.

  • Configure privileges to allow your API keys to access ArcGIS services, content, and functionality.

  • Set the expiration date and referrer URLs of an API key.

  • Manage API keys using the item page of your API key credentials.

Prerequisites

Steps

Sign in to your portal

You use your portal to create and manage items, including API key credentials.

  1. Sign in to your portal with your ArcGIS account.

Create a new item

  1. In your portal, click Content > My content > New item.

  2. Click Developer credentials > API key credentials and click Next.

Set the expiration date and referrers

API key credentials generate long-lived access tokens called API keys. API keys are valid for up to one year, and their expiration date is set when they are generated. You can also set referrers on an API key, which restrict the key to only be usable from authorized domains.

  1. In the Create developer credentials window, click on the Expiration date field. Set the expiration date of the access token to one month from today's date.

    Expiration date selector
  2. Set the Referrers field to the web domains you would like to restrict the access token to. This is highly recommended for security purposes. To learn more about referrers, go to API key credentials.

    Referrer selector
  3. Click Next.

Select privileges

You can configure the settings of API key credentials to configure the privileges of access tokens. For an access token to work in your application, it needs to have the correct privileges to access the content and services your app is using. Select the privileges you require to apply them to your API key access token.

  1. In the Create developer credentials > Privileges window, browse the available privileges.

    Privileges window
  2. Browse the table below to view the available privileges, privilege strings, and descriptions based on your account type:

    CategoryLabelPrivilege stringDescription
    BasemapsBasemap styles servicepremium:user:basemapsAllow application to access the basemap styles service. Learn more
    BasemapsStatic basemap tiles (beta)premium:user:staticbasemaptilesAllow application to access the static basemap tiles service. Learn more
    Data enrichmentGeoEnrichment servicepremium:user:geoenrichmentAllow application to access the GeoEnrichment service. Learn more
    ElevationElevation service (beta)premium:user:elevationAllow application to access the elevation service.
    GeocodingGeocode (stored)premium:user:geocode:storedAllow application to access the geocoding service and perform stored geocodes. Learn more
    GeocodingGeocode (not stored)premium:user:geocode:temporaryAllow application to access the geocoding service and perform geocodes that are not stored. Learn more
    PlacesPlace findingpremium:user:placesAllow application to access the places service. Learn more
    RoutingRoutingpremium:user:networkanalysis:routingAllow application to access the routing service and perform standard routing operations. Learn more
    RoutingClosest facilitypremium:user:networkanalysis:closestfacilityAllow application to access the routing service and perform closest facility routing operations. Learn more
    RoutingLocation allocationpremium:user:networkanalysis:locationallocationAllow application to access the routing service and perform location allocation operations. Learn more
    RoutingOptimized routingpremium:user:networkanalysis:optimizedroutingAllow application to access the routing service and perform optimized routing operations. Learn more
    RoutingOrigin/destination cost matrixpremium:user:networkanalysis:origindestinationcostmatrixAllow application to access the routing service and generate travel cost matrices. Learn more
    RoutingService areapremium:user:networkanalysis:serviceareaAllow application to access the routing service and generate service areas. Learn more
    RoutingMulti-vehicle routingpremium:user:networkanalysis:vehicleroutingAllow application to access the routing service and perform fleet routing operations. Learn more
    RoutingLast milepremium:user:networkanalysis:lastmiledeliveryAllow application to access the routing service and perform routing operations for last mile delivery. Learn more
  3. Select the the privileges required by your application and click Next.

Select items (optional)

If your application will require access to specific private items, you will need to configure your developer credentials to access them. The Item access menu allows you to browse your portal's content and grant your API key access to specific items.

  1. If your token does not require item access, click Skip.

  2. In the Grant item access window, click Browse items.

    Item access button
  3. Select the items you want to grant access to. You can select up to 100 items in this menu.

    Item access menu
  4. Click Add items.

Save the item

After configuring the properties of your API key credentials, you can save the credentials as a new item.

  1. In the Create developer credentials window, set the following properties:

    • Title: My API key credentials
    • Folder: Developer credentials (Create a new folder)
    • Tags: Add tags related to the privileges of the credentials.
    • Description: Describe the application that these developer credentials will be used in.
    API key credential details

    Click Next.

  2. In the Summary window, review the properties, privileges, and item access you have set. If you selected any privileges with a personal scope, you must acknowledge the security implications before moving forward.

    Personal privileges summary screen
  3. Click Next.

Copy the API key

  1. In the Create developer credentials > Generate API key window, select Generate the API key and go to item details page. I am ready to copy and save the key.

    Generate the key
  2. Click Next.

  3. Copy the API key from the window that appears and paste it into your application.

    Copy the key

Manage your credentials (optional)

After creating an API key credentials item, its properties can be managed at any time by going to the item page. The Settings menu allows you to manage the following properties of API keys:

  • Generate a secondary API key: You can generate a secondary API key in the same credentials with identical privileges and a new expiration date.

  • Regenerate an API key: If you lose access to an API key, you can regenerate it with a new expiration date.

  • Invalidate an API key: You can invalidate an API key so that it no longer functions in applications.

  • Edit privileges: You can edit the privileges of your API key credentials to adjust the authorization level of your API keys.

  • Edit item access: You can edit the items that your API key credentials are authorized to access.

  • Monitor key usage: You can monitor the usage of your API keys to track their consumption of services and view billing information. To learn more, go to API key credentials.

What's next?

Learn how to use your API key to access secure ArcGIS resources in the following guides:

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