Select to view content in your preferred language

arcgis 3.14 add authorization header and preserve query parameters via setRequestPreCallback

80
1
Thursday
DanielJennings
New Contributor

Greetings!!

I have been tasked with adding an Authorization header to our layer query request.

Referencing Solved: Re: How to set headers for esriRequest using .setR... - Esri Community I managed to get the setRequestPreCallback set and the Authorization header added.  

However, when the callback function is fired, it only has 4 of the 9 needed query parameters for the link to work.  

Is there a method of recovering the missing query parameters??  

We are using arcgis 3.14.  

Thank you,

-Daniel

0 Kudos
1 Reply
VenkataKondepati
Occasional Contributor

In 3.14 you can’t. esri.config.defaults.io.setRequestPreCallback fires before ArcGIS JS finalizes the request, so you’ll only see a partial content object; the library appends the rest (e.g., f, where/outFields, token, cache-buster, JSONP bits) after your callback. There’s no API to “recover” those missing params in that hook.

Practical options:

  1. Use a proxy to add the Authorization header server-side. This is the most reliable with 3.x (no CORS/header headaches, no param timing issues).

  2. Bypass QueryTask/FeatureLayer and call the endpoint yourself with esri.request, where you supply the full payload and header:

require(["esri/request"], function(esriRequest){
  esriRequest({
    url: layerUrl + "/query",
    content: {
      where: "GlobalID='" + guid + "'",
      outFields: "*",
      returnGeometry: false,
      f: "json"
    },
    headers: { "Authorization": "Bearer " + token }
  }, { usePost: true }).then(handle, err);
});

 

  1. Upgrade (if you can) to a later 3.x or 4.x, where header handling and CORS behavior are cleaner. Still, for 3.x the proxy remains the simplest fix.

Keep using the pre-callback only to inject the header; don’t rely on it to inspect the final query. If you need to see/shape every param, build the request yourself or proxy it.

0 Kudos