Select to view content in your preferred language

498 Invalid Token error with esriConfig.apiKey

1139
5
Jump to solution
11-20-2023 07:58 AM
roberth
New Contributor

I'm receiving an error when providing an API Key using the JS SDK version 4.27. Same behavior for 4.25. This had previously been working:

loadModules([
    'esri/config',
    'esri/Map',
    'esri/views/MapView', 
]).then(([esriConfig, Map, MapView]) => {
    esriConfig.apiKey = 'xxxxx';

    const map = new Map({
        basemap: 'topo-vector',
    });
    
    const view = new MapView({
        viewDiv: 'test',
        map: map
    });
});

 
Obviously, substituting our actual API key for 'xxxxx'. This is hitting the following URL:

https://cdn.arcgis.com/sharing/rest/content/items/7dc6cea0b1764a1f9af2e679f642f0f5/resources/styles/...

roberth_0-1700495541615.png

Without providing an API key, it works. 

This had been working previously, as my developer account has historical usage. I've also tested a different API key and receive the same error. Structurally there's not much else going on in the code, and it's the same approach mentioned by official documentation: https://developers.arcgis.com/javascript/latest/tutorials/display-a-map/

roberth_1-1700495611530.png

 

 

0 Kudos
1 Solution

Accepted Solutions
LaurenBoyd
Esri Contributor

@roberth does your API work when you try to use it in the tutorial's solution? https://developers.arcgis.com/javascript/latest/tutorials/display-a-map/ 

Wondering if this is specific to your application. Also, was there a specific version of the JavaScript Maps SDK where this stopped working for you since you mentioned this had been working previously?

Lauren

View solution in original post

5 Replies
LaurenBoyd
Esri Contributor

@roberth does your API work when you try to use it in the tutorial's solution? https://developers.arcgis.com/javascript/latest/tutorials/display-a-map/ 

Wondering if this is specific to your application. Also, was there a specific version of the JavaScript Maps SDK where this stopped working for you since you mentioned this had been working previously?

Lauren
roberth
New Contributor

Lo and behold it works now. I think it was just a temporary service disruption.

0 Kudos
LaurenBoyd
Esri Contributor

Glad to hear it works now! That is possible it could have been a service issue.

Lauren
0 Kudos
fenglinhan
Emerging Contributor

I am using apiKey and also app token to identify my app in my angular arcgis application.

 

but when i am loading a image layer https://env1.arcgis.com/arcgis/rest/services/Sentinel2_10m_LandCover/ImageServer

the key/token is causing the imagelayer can not be loaded. 
and if i delete the apikey/token, i got a arcgis online login popup window, i can loaded this image layer after the user/pass is filled in the popup.

how to solve this problem? how to avoid the arcgis online login popup and load this imagelayer?
can i use usersession to achieve this?

0 Kudos
Noah-Sager
Esri Regular Contributor

That's very strange. It sounds like something happened to the API Key. I would try making a new one and testing it out. The workflow still works (I just checked). But I would also recommend not using an API Key in the app if it's not needed.

0 Kudos