When I pass the tags argument next to the URL or payload on an HTTP call. We can able to filter the results with tags but we missing the custom header value on the request.
let res = http.get(${BaseURL}/
,{tags: { myTransaction: ‘JP_01_HomePage’ }},homePageHeader);
When I switch the header and tags argument like below.
let res = http.get(${BaseURL}/images/2016/jacarandaplus.png
,homePageHeader,{tags: { myTransaction: ‘JP_01_HomePage_Image’ }});
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
Now we missed the tag but got the header on the HTTP request.
Guide me on how to use both custom header and user-defined tags with the same HTTP call
you can do something like this:
{
method: ‘GET’,
url: ‘some url’,
params: {
headers: {
Authorization:Bearer ${token}
,
‘Content-Type’: ‘application/json’,
},
tags: { request_name: ‘get url’ },
},
},
1 Like
@aakash.gupta
Use Case :
If I introduce a “params” to wrap the header and tags, then I need to create a lot of unique params. For me, a set of requests has the same header values but different user-defined tags. Because it’s a web application, not an API request. How to handle that situation
const header = {
header1: ‘header value’,
header2: ‘header value’
}
const request1 = {
method: ‘GET’,
url: ‘some url’,
params: {
headers,
tags: { tag1: ‘tag1 value’ },
},
};
const request2 = {
method: ‘GET’,
url: ‘some url’,
params: {
headers,
tags: { tag2: ‘tag2 value’ },
},
};
1 Like
Hi Akash,
I tried the above solution as follows.
const header = {
header1: ‘header value’,
header2: ‘header value’
}
const request1 = {
method: ‘GET’,
url: ‘some url’,
params: {
headers,
tags: { tag1: ‘tag1 value’ },
},
};
I am getting below error
ERRO[0009] ReferenceError: params is not defined
Fix this
![image](https://us1.discourse-cdn.com/grafana/original/2X/f/fc77768350b40d5c92f8c0b906641e0635f34807.png)
Try like this. Define headers and tags separately and call the param value on the request argument
const myHeaderParam=
{
headers: {
‘header1’:‘header1Value’,
‘header1’:‘header1Value’,
},
tags: { myTag: ‘Test’ , myTag2:‘Please’},
};
let testResponse= http.post(myURL
,
{
action: ‘payload1’,
action2: ‘payload1’,
},myHeaderParam);
1 Like
@Gerard it seems to be bit confusing for me. here the use case is a set of requests has the same header values but different user-defined tags. those set of requests are placed under one groups. So i want to place the header values under params and call it wherever required and tag values will be different for individual apis. But in your solution you placed headers and tags under param value , while calling the header param for every requests how the tag value will be assigned to every requests.
const myHeaderParam=
{
headers: {
‘header1’:‘header1Value’,
‘header1’:‘header1Value’,
},
tags: { myTag: ‘Test’ , myTag2:‘Please’},
};
let testResponse= http.post(myURL,
{
action: ‘payload1’,
action2: ‘payload1’,
},myHeaderParam);
let testResponse= http.post(myURL2,
{
action: ‘payload2’,
action2: ‘payload2’,
},myHeaderParam);
Please refer the HTTP request API document.
Params is a object therefore if you want to acheive the use case;
Option 01:
Define seperate Param with differnt tag values and the same header and call it where ever required
Option 02:
Define the header value seperate, and assign additional tag values (use of Object.assign()) and where it required