How to pass Headers from two different variables and combained them into headers params

I have defined a variable with headers like this…

let params2 = {
       'accept': 'application/json',
       'content-type': 'application/json',
       'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
       'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
       'sec-ch-ua-mobile': '?0',
       'sec-ch-ua-platform': '"Windows"',
      };

Above listed variable params2 used for each API request, and I want to use another one header with “Referal” URL this is different for some APIs like listed below

let params3 = { ‘Referer’:‘https://staging.url.com/dashboard/’ }

so how to combine both into headers params…

avatar = {
  method: 'GET',
  url: `https://staging.url.com/api/v1/users/avatar`,
  params: {
    headers: params ,    
    },
    params: {
      headers: { 'Referer':'https://staging.url.com/dashboard/'},
      },
};

@venkatareddy

You can use:

...
params: {
  headers: Object.assign({}, params2, params3)
}
...
1 Like

Hi @bandorko

Thanks for your replay… I got it. its working…

{ headers: Object.assign({}, params, {'Referer':'https://staging.url.com/dashboard/'}) }
1 Like