How to check header is exist or not ?

Not applicable

I am unable to find context.getVariable("request.header.check") is exist or not.

If we are sending empty value for check in header.

context.getVariable('request.header.check.values.count') i am always getting 0

Solved Solved
0 7 5,573
1 ACCEPTED SOLUTION

Hello @Guru Venkatesh

I am a little confused as to what you are trying to do. Are you trying to check if any headers are received in the request or if a specific header called 'check' is received?

I am guessing that you meant the latter.

If you are sending a HTTP header called 'check' in the request with no value in it, then request.header.check.values.count will show zero because as far as Apigee is concerned, there is no value in the header that is being sent.

Instead, if you send the below request :

curl -X GET -H "Content-Type: application/xml" -H "check: 1" -H "check: 11" "http://test.apigeeserver.com:80/v1/test"

then the value of request.header.check.values.count will be '2' because two headers called 'check' have been received in the request.

You can then use the variable request.header.check.values to get an array of all the values of the check header received in the request.

Does this clear your doubts?

View solution in original post

7 REPLIES 7

Hello @Guru Venkatesh

I am a little confused as to what you are trying to do. Are you trying to check if any headers are received in the request or if a specific header called 'check' is received?

I am guessing that you meant the latter.

If you are sending a HTTP header called 'check' in the request with no value in it, then request.header.check.values.count will show zero because as far as Apigee is concerned, there is no value in the header that is being sent.

Instead, if you send the below request :

curl -X GET -H "Content-Type: application/xml" -H "check: 1" -H "check: 11" "http://test.apigeeserver.com:80/v1/test"

then the value of request.header.check.values.count will be '2' because two headers called 'check' have been received in the request.

You can then use the variable request.header.check.values to get an array of all the values of the check header received in the request.

Does this clear your doubts?

Thanks @Hari for reply. If i pass no value in HTTP header 'check' .Is there any way to confirm 'check' is available in header?

@Guru Venkatesh

You can check the names of all the headers received in the request using the variable 'request.headers.names'. This variable will give you an array containing the names of all the headers received in the HTTP request. You can then use javascript to see if you have received any specific header that you are looking for.

You can find the list of all the variables in Apigee here.

I tried with request.headers.names still I am unable to print header with empty value

I tried with context.proxyRequest.headers as well but I didn't get the result


I want to display all headers even though if header doesnt have the value

so let us assume we have two headers check,check2. check is having empty value and check2 is having data 'sample'

if I am trying to print all headers

print(context.getVariable('request.headers.names'));


I am getting only check2.

Is there any possibility to get check header which is having empty value?headers.jpg

please find image for headers for understanding

@Guru Venkatesh

I see that you are using request.headers.names. You should be using request.header.names.

I verified both request.headers.names,request.header.names

request.headers.names is available in Apigee document to print key and value pairs of all headers

I also tried with request.header.names it is printing only key values of headers


both request.headers.names,request.header.names are not able to print empty value.

we find the issue is with postman.postman itself is not passing headers to apigee if we are passing values as empty.Thanks @Hari for your support