How can I see the service callout response headers in javascript?

Not applicable

I tried

var resheader = context.getVariable("calloutResponse.header");

but i am not bale to see the headers which is coming from back end ,

Can anyone know how can we fetch the headers from callout response?

Thanks,

Ambili

Solved Solved
1 4 1,602
1 ACCEPTED SOLUTION

Not applicable

Here is a JSC snippet that will print all the headers in the response:

var headerNames = context.getVariable("response.headers.names") + "";
headerNames.split(", ").sort().forEach(function(headerName) {
    if (headerName)
        print(headerName+":"+context.getVariable("response.header."+headerName));
});

Change the name of response.headers to whatever you named your callout response.

View solution in original post

4 REPLIES 4

@Ambili v nair

See similar post here.. Let us know if it helps you.

Not applicable

Here is a JSC snippet that will print all the headers in the response:

var headerNames = context.getVariable("response.headers.names") + "";
headerNames.split(", ").sort().forEach(function(headerName) {
    if (headerName)
        print(headerName+":"+context.getVariable("response.header."+headerName));
});

Change the name of response.headers to whatever you named your callout response.

Thanks David,

now I am able to see the Headers ,

but i need header + values

I tried

response.header.{header_name}.value

response.header

response.headers.values

response.headers.names.values

but nothing is working for me , Can you suggest some way to fetch header + values ?

context.getVariable("response.header."+headerName) bit from @David Allen's code gives you the value of the header.

E.g. if the header name is Content-Length, then this will give you the value:

var contentLengthValue = context.getVariable('response.header.Content-Length');