<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Questions regarding apiKey usage on layers loaded from AGOL and requests to utility.arcgis.com in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/questions-regarding-apikey-usage-on-layers-loaded/m-p/1699793#M88402</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am having some trouble with the authentication of a layer loaded from a Portal item when using the ArcGIS Maps SDK for JavaScript. I was hoping you could clarify if I’m missing a configuration step or if I’ve encountered a known behaviour.&lt;/P&gt;&lt;P&gt;The Scenario: I am loading a specific layer from a Portal item and providing an apiKey directly in the portalItem configuration:&lt;/P&gt;&lt;PRE&gt;const layer = await Layer.fromPortalItem({&lt;BR /&gt;  portalItem: {&lt;BR /&gt;    id: "MY_LAYERS_PORTAL_ID",&lt;BR /&gt;    apiKey: "MY_SPECIFIC_API_KEY"&lt;BR /&gt;  }&lt;BR /&gt;});&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;In my application, I also use a global request interceptor that manages dynamic tokens for other general services by updating esriConfig.apiKey.&lt;/P&gt;&lt;PRE&gt;esriConfig.request.interceptors.unshift({&lt;BR /&gt;  async before() {&lt;BR /&gt;    esriConfig.apiKey = await getEsriToken();&lt;BR /&gt;  }&lt;BR /&gt;  urls: [&lt;BR /&gt;    'https://www.arcgis.com',&lt;BR /&gt;    'https://snla.maps.arcgis.com',&lt;BR /&gt;    'https://services-eu1.arcgis.com',&lt;BR /&gt;    'https://utility.arcgis.com',&lt;BR /&gt;    'https://services-eu1.arcgis.com',&lt;BR /&gt;    'https://elevation.arcgis.com',&lt;BR /&gt;    'https://route-api.arcgis.com',&lt;BR /&gt;    'https://geocode.arcgis.com'&lt;BR /&gt;  ]&lt;BR /&gt;});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The Problem: I've noticed that while the initial portal metadata requests (sharing/rest) correctly use the provided apiKey, the subsequent request for the layer data (routed through the utility service proxy) behaves differently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;URL: &lt;EM&gt;&lt;A href="https://utility.arcgis.com/usrsvcs/servers/PORTAL_ID/rest/services/SERVICE_NAME/FeatureServer/0" target="_blank"&gt;https://utility.arcgis.com/usrsvcs/servers/PORTAL_ID/rest/services/SERVICE_NAME/FeatureServer/0&lt;/A&gt;&lt;/EM&gt; &lt;STRONG&gt;Uses the key from esriConfig.apiKey&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Observation: If I remove the utility.arcgis.com domain from my global interceptor, this request triggers an ArcGIS login prompt, suggesting it isn't using the apiKey I provided to the layer.&lt;/LI&gt;&lt;LI&gt;Conflict: If my global interceptor is active, the request uses the global esriConfig.apiKey instead of the layer-specific one, which causes an authentication failure for this private layer.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;My Questions:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Should requests routed through utility.arcgis.com automatically inherit the apiKey provided to the PortalItem or Layer?&lt;/LI&gt;&lt;LI&gt;Am I doing something wrong in how I'm passing the key? I tried setting the apiKey on the resulting layer instance or the portal object as well, without success.&lt;/LI&gt;&lt;LI&gt;Is there a recommended pattern for maintaining a global API key while allowing certain layers to use their own specific keys for proxied services?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Emil Aura&lt;/P&gt;</description>
    <pubDate>Mon, 04 May 2026 10:49:54 GMT</pubDate>
    <dc:creator>EmilAura</dc:creator>
    <dc:date>2026-05-04T10:49:54Z</dc:date>
    <item>
      <title>Questions regarding apiKey usage on layers loaded from AGOL and requests to utility.arcgis.com</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/questions-regarding-apikey-usage-on-layers-loaded/m-p/1699793#M88402</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am having some trouble with the authentication of a layer loaded from a Portal item when using the ArcGIS Maps SDK for JavaScript. I was hoping you could clarify if I’m missing a configuration step or if I’ve encountered a known behaviour.&lt;/P&gt;&lt;P&gt;The Scenario: I am loading a specific layer from a Portal item and providing an apiKey directly in the portalItem configuration:&lt;/P&gt;&lt;PRE&gt;const layer = await Layer.fromPortalItem({&lt;BR /&gt;  portalItem: {&lt;BR /&gt;    id: "MY_LAYERS_PORTAL_ID",&lt;BR /&gt;    apiKey: "MY_SPECIFIC_API_KEY"&lt;BR /&gt;  }&lt;BR /&gt;});&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;In my application, I also use a global request interceptor that manages dynamic tokens for other general services by updating esriConfig.apiKey.&lt;/P&gt;&lt;PRE&gt;esriConfig.request.interceptors.unshift({&lt;BR /&gt;  async before() {&lt;BR /&gt;    esriConfig.apiKey = await getEsriToken();&lt;BR /&gt;  }&lt;BR /&gt;  urls: [&lt;BR /&gt;    'https://www.arcgis.com',&lt;BR /&gt;    'https://snla.maps.arcgis.com',&lt;BR /&gt;    'https://services-eu1.arcgis.com',&lt;BR /&gt;    'https://utility.arcgis.com',&lt;BR /&gt;    'https://services-eu1.arcgis.com',&lt;BR /&gt;    'https://elevation.arcgis.com',&lt;BR /&gt;    'https://route-api.arcgis.com',&lt;BR /&gt;    'https://geocode.arcgis.com'&lt;BR /&gt;  ]&lt;BR /&gt;});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The Problem: I've noticed that while the initial portal metadata requests (sharing/rest) correctly use the provided apiKey, the subsequent request for the layer data (routed through the utility service proxy) behaves differently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;URL: &lt;EM&gt;&lt;A href="https://utility.arcgis.com/usrsvcs/servers/PORTAL_ID/rest/services/SERVICE_NAME/FeatureServer/0" target="_blank"&gt;https://utility.arcgis.com/usrsvcs/servers/PORTAL_ID/rest/services/SERVICE_NAME/FeatureServer/0&lt;/A&gt;&lt;/EM&gt; &lt;STRONG&gt;Uses the key from esriConfig.apiKey&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Observation: If I remove the utility.arcgis.com domain from my global interceptor, this request triggers an ArcGIS login prompt, suggesting it isn't using the apiKey I provided to the layer.&lt;/LI&gt;&lt;LI&gt;Conflict: If my global interceptor is active, the request uses the global esriConfig.apiKey instead of the layer-specific one, which causes an authentication failure for this private layer.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;My Questions:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Should requests routed through utility.arcgis.com automatically inherit the apiKey provided to the PortalItem or Layer?&lt;/LI&gt;&lt;LI&gt;Am I doing something wrong in how I'm passing the key? I tried setting the apiKey on the resulting layer instance or the portal object as well, without success.&lt;/LI&gt;&lt;LI&gt;Is there a recommended pattern for maintaining a global API key while allowing certain layers to use their own specific keys for proxied services?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Emil Aura&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2026 10:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/questions-regarding-apikey-usage-on-layers-loaded/m-p/1699793#M88402</guid>
      <dc:creator>EmilAura</dc:creator>
      <dc:date>2026-05-04T10:49:54Z</dc:date>
    </item>
  </channel>
</rss>

