Help in pass variables to routes

Issue : I want to pass a value from dropdown in workspace. And i want to pass it to pass the input to an url declared in routes. But ut does not seem work with this /donation/monthly/average/currency/{{Currency.selectedValue}}

Code :'/donation/monthly/average/currency:currency_code', (req, res, next) => {

  const currency_code = req.params.currency_code;
  console.log("currency_code", currency_code)


Hello @Jaspreet_Singh,

I need more information to guide you toward the right decision.

  • What agent are you using?

Kind regards,

Okay so a bit more info. What I did was added this code inside routes declared this inside our forestadmin code and I need to pass it variable from a dropdown in frontend to this route declared in code.'/donation/monthly/average/currency/:currency_code', (req, res, next) => {})

This route “/donation/monthly/average/currency/{{Currency.selectedValue}}” is used in a chart on frontend in workspace.

Hey @Jaspreet_Singh,

There is a forest-context-url header that you could use, that might help you get the information you seek :slight_smile:

For more as you can see in the picture I am trying to pass value from dropdown to url

Code Snippet routes in the admin code from which frontend is connected

@vince @morganperre Hey a friendly reminder. Can you provide with a possible solution?

Hi @Jaspreet_Singh,

At the moment it’s not possible to template chart url, so you can’t pass value inside the api chart but like I said in my previous message, you should be able to do something like that:'/donation/monthly/average', (req, res, next) => {
  const contextUrl = req.headers['forest-context-url'];
  const queryParams = contextUrl
    .reduce((acc, queryParam) => {
      const [paramName, paramValue] = queryParam.split('=');
      return {
        [paramName]: paramValue,
     }, {});
  console.log('Currency', queryParams['Currency.selectedValue']);
1 Like

@vince Thanks for reply.
contextUrl is being shown as undefined in console.log.
const contextUrl = req.headers['forest-context-url'];

Is there any other solution for the same?

And adding this allowedHeaders: ['Forest-Context-Url'], to corsConfig is crashing frontend.

Okey you are right it seems it’s missing on the api charts.
So it’s a feature request. I’ll let you know once it is possible