Select to view content in your preferred language

Problems with API key in MapLibre: 401 / invalid token

330
1
01-31-2026 07:54 AM
Labels (1)
hess8
by
New Contributor

I'm just starting with MapLibre and ESRI, and can't get it to recognize my api key.

My api key has basemap and basemap styles privileges. 

With the simple tutorial code

 

apiKey = '<api key>';

const map = new maplibregl.Map({
  container: "map", // the id of the div element
  zoom: 2, // starting zoom
  center: [-20, 30] // starting location [longitude, latitude]
});

const basemapStyle = maplibreArcGIS.BasemapStyle.applyStyle(map, {
  style: "arcgis/outdoor",
  token: apiKey
});

 

It generates url 

 

https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/arcgis/outdoor?f=json&echoToken=false&token=AAPT

 

But returns 401 / invalid_token error.  The key is valid.  Any ideas on how to debug this?

Tags (2)
0 Kudos
1 Reply
John-Foster
Esri Contributor

@hess8 it really looks like your API key is no good. Check your settings and verify you have the required privilages, expiration date is in the future, and if you have any referrers set to make sure they match your origin.

If I run your URL above with my API key the service responds with 200, so you can use this technique to test your api key

https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/arcgis/outdoor?f=json&ech....

If you do not get it work work can you post the server response JSON here it might provide additional information.

 

--jf
0 Kudos