<?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 Re: pass api-key in header to extract GeoJson in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1331840#M82293</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for your reply. I am using python flask server to return GeoJson response as follows:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        if format == 'json':
            response = Response(df_forecast_site_status.to_json(), mimetype='application/json')
        else:
            response = Response(df_forecast_site_status.to_csv())
        response.headers.add('Access-Control-Allow-Origin', '*')
        return response&lt;/LI-CODE&gt;&lt;P&gt;It works if environment is in dev or staging environment where x-api-key is not required. Soon as I add custom header, it fails with CORS error.&lt;/P&gt;&lt;P&gt;Shingo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Sep 2023 16:04:32 GMT</pubDate>
    <dc:creator>Shingo-Ikeda</dc:creator>
    <dc:date>2023-09-24T16:04:32Z</dc:date>
    <item>
      <title>pass api-key in header to extract GeoJson</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1329610#M82240</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to pass api-key in header using esriConfig.request.interceptors as well as esriConfig.request.trustedServers in TypeScript using JSAPI 4.x, however, it doesn't return the geojson results as I am able to extract through postman.&amp;nbsp; Any crue what is causing CORS error through this request method?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    esriConfig.request.trustedServers.push(this.base_url);
    esriConfig.request.interceptors.push({
      urls: geojson_url,
      before: function (params: any) {
        params.requestOptions.headers = {
          'x-api-key': this.x_api_key,
          'Access-Control-Allow-Origin': this.base_url,
        };
      },    
      after: function(response) {
        if (!response.ssl) {
          response.ssl = true;
        }
        const geojsonLayer = new GeoJSONLayer({
          title: 'Forecast Kind',
          url: response.data, 
          popupTemplate: template_forecast_kind,
          visible: false,
          outFields:["*"] 
        });
      },
      headers: {
        'x-api-key': this.x_api_key,
        'Access-Control-Allow-Origin': '*',
      },
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error shows:&lt;/P&gt;&lt;P&gt;Access to fetch at 'https://.....com/sites/current_forecast_status' from origin '&lt;A href="http://localhost:4200/" target="_blank" rel="noopener nofollow noreferrer"&gt;http://localhost:4200&lt;/A&gt;' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shingo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 14:38:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1329610#M82240</guid>
      <dc:creator>Shingo-Ikeda</dc:creator>
      <dc:date>2023-09-18T14:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: pass api-key in header to extract GeoJson</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1330063#M82244</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/77421"&gt;@Shingo-Ikeda&lt;/a&gt;&amp;nbsp;, thanks for asking your question here.&amp;nbsp;&amp;nbsp;Access-Control-Allow-Origin is a response header and won't be honored if sent as part of the request.&amp;nbsp; It needs to be set as a response header on the web server (not the application code) allowing the origin of you application. This webpage has instructions on how to set CORS up on multiple different web servers, however, you may want to check to official docs for whatever server you happen to be using.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.w3.org/wiki/CORS_Enabled" target="_blank"&gt;https://www.w3.org/wiki/CORS_Enabled&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin" target="_blank" rel="noopener"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2023 12:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1330063#M82244</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-09-19T12:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: pass api-key in header to extract GeoJson</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1331840#M82293</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/507049"&gt;@Sage_Wall&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thank you for your reply. I am using python flask server to return GeoJson response as follows:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        if format == 'json':
            response = Response(df_forecast_site_status.to_json(), mimetype='application/json')
        else:
            response = Response(df_forecast_site_status.to_csv())
        response.headers.add('Access-Control-Allow-Origin', '*')
        return response&lt;/LI-CODE&gt;&lt;P&gt;It works if environment is in dev or staging environment where x-api-key is not required. Soon as I add custom header, it fails with CORS error.&lt;/P&gt;&lt;P&gt;Shingo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 16:04:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/pass-api-key-in-header-to-extract-geojson/m-p/1331840#M82293</guid>
      <dc:creator>Shingo-Ikeda</dc:creator>
      <dc:date>2023-09-24T16:04:32Z</dc:date>
    </item>
  </channel>
</rss>

