How to pass dynamic headers in resource query through JS

  • Goal: Call a query resource in JS, passing a headers to be used in the REST request
  • Details:

I'm very new to ReTool and hoping this is an obvious thing I've just not found the answer to. I have a REST API resource (callMyREST) which works perfectly fine when I use it with events, etc. But I'd like to call it from some JS code. Like callMyREST and passing headers through

callyMyREST.trigger(
    additionalScope:{
    
     }
) 

and have that REST API resource use that value in one of its Headers like
https://apiurl.com{ x-buser-id: "abcd"}

But for some reason, I'm struggling to find how I pass the headers and define it within the resource. Is there a how-to guide I'm overlooking somewhere? Thanks for any guidance here!

Hi @Dk1, welcome to the forum! :wave:
I made a small edit to your topic to make the code blocks and inline a bit more legible. Do you mind sharing a screenshot with your existing Resource settings?

Here is an example of a Resource query where we'll pass the value of xBuserId for the key x-buser-id:


Note: Ignore the red, xBuserId is not defined here but it will be when we trigger it.

To trigger the app we would need the following trigger:
Screenshot 2024-09-25 at 3.36.56 PM

The trigger can also be on an event handler. I just put it inside a JS query for simplicity.

Success:
Screenshot 2024-09-25 at 3.38.00 PM

Note: HttpBin just echoes the request, I used this to show that the header was in fact sent in.