Skip to main content
13-Aquamarine
January 24, 2017
Question

Is there a way to access response headers from a GetJSON() call in a service?

  • January 24, 2017
  • 2 replies
  • 2627 views

I'm working with an external service where I request a csrf token via request header and the service returns the token in the response headers.  I can't see how to access the response headers in my Thing service.

For example, here's the call to GetJSON:

var params = {

    headers: {'x-csrf-token' : 'fetch'} /* JSON */,

ignoreSSLErrors: true /* BOOLEAN */,
url: me.baseURL /* STRING */,
password: me.password /* STRING */,
username: me.userId /* STRING */

};

// result: JSON

var result = Resources["ContentLoaderFunctions"].GetJSON(params);

I can see my request headers in the output if I logger.warn(JSON.stringify(result)); (i.e.  {"headers":{"x-csrf-token":"fetch"}) but when I execute the same GET from POSTMAN and look at the response headers, I see the other system's returned value for x-csrf-token.

Is there a way to access the response headers in a service?

Thanks,

Steve Ashley

2 replies

1-Visitor
January 25, 2017

Hi Steve,

I don't know if that's the reason, but it's not the same doing a request with POSTMAN and with TW, as POSTMAN automatically adds requests headers which can affect to response headers.

Carles.

1-Visitor
January 25, 2017

Hi Steve,

I believe there is no such possibility OOTB now (but I can be wrong). The easiest way to achieve that is to create a very simple extension in Java with generic service to send HTTP requests. Then you can do pretty much anything with response. This is the most clean and straightforward solution.

Regards,

J.