Search code examples
paginationiterationtalendrecurly

Talend - How To Retrieve Response Headers From tRestClient


I'm using tRestClient to pull data from a REST API which returns data in pages of up to 200 items each. The link to the next page is provided in the response header.

How do I access the response header using tRestClient?

From what I can see, the only data returned is located in the body of the response.

Note: the same call from Postman verifies the existence of a response header labeled "Link" which contains the necessary data.


Solution

  • I found the answer in a post in the Talend Community

    The response headers are stored in a global variable which is only actually populated when the response body is passed over to something such as a tLogRow (even if there isn't any content in the response body).

    The global variable can be accessed via:

    ((java.util.Map<String,java.util.List<String>>)globalMap.get("tRESTClient_1_HEADERS")).get("NAME_OF_HEADER_FIELD_HERE").get(INDEX_HERE).toString();
    

    where "NAME_OF_HEADER_FIELD_HERE" is the key (string) of the specific header you are interested in and "INDEX_HERE" is the integer index (0-based) of a specific value in the list of values associated with that particular header.

    In this case we are explicitly converting the result to a string which is then used elsewhere.