Talend - How To Retrieve Response Headers From tRestClient - pagination

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.

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.

Related

How do you use REST/HTTP with a body as a source in an ADF copy activity?

I cannot seem to be be able to use a REST-source with the the body as dynamic content from a previous lookup-activity. The body content in the REST API call will be messed up with "" and "\n" characters. I noticed data factory automatically adds braces to dynamic content:
Removing the braces from the code view results in an error when running the pipeline. I have tested the same API call with a web activity, in which the body will be formatted correctly:
However, I don't know how you can save the response as a file from a web activity. In recap, I want to dynamically pass the Body to a REST API and save the response as a json file. How should this be achieved?
I haven't used this scenario myself, but two things come to mind:
1) Assuming the body needs to be JSON, so you may need to convert the lookup value [which I assume is a string] using the json expression. Something like
#{json(activity('Lookup1').output.value)}
2) Under additional headers, you may need to add an entry to specify Content-Type: application/json

Creating an array from a get webhook response nested json

The current Zapier steps i have set up creates a GET request to an external service. that service replies with a list of data that is nested. My end step i need to do is make multiple PUT requests to another API with part of the URL being a value from the response from the GET. There is not a fixed number of id’s/times that it will need to PUT. 
Currently if i do it with just the GET then the next step is the PUT it puts all of the values of the ID i need to put at the end of the API url as just a comma separated list. I need them to make separate PUT requests for Each ID.
Any help would be greatly appreciated.
This shows the response to the GET request (Images shows only the first part. There will are more in the response)
This is the PUT request. It currently puts them as a comma separated list. which causes an error. each of the values needs to process as a separate PUT.
​
You may want to consider writing your own code step to format the nested data into an array of objects (JSON). You could then return the data to output and achieve the effect you're looking for, where the next Step runs a PUT request for each item in your output array.
Here are Zapier's notes on this strategy:
Setting the output to an array of objects will run the subsequent steps multiple times — once for each object in the array. If Code by Zapier is the Zap's trigger and an empty array is returned, nothing happens. You can think of it like a polling trigger that did not get any results in the HTTP response. This functionality is exclusive to triggers — returning an empty array in a Code by Zapier action does not have the same effect.

Encoding is happening while sending parameter from Post request in Jmeter

I have a Post request in Jmeter in which, ViewState parameter is passing but value for that parameter is combination of alphabates, number, special characters . so while send that parameter request is encoding the special character for e.g. i have forward slash in paramter so while sending it is converting it to %2F and that leads in failing the request
Solution i have tried is:
uncheck URL Encode check box
UTF-8 in content encoding
for ViewState providing ${__urldecode('${viewState}')} value as Parameter value, which(viewState) i am fetching from previous response
used replace function in Parameter value
So what i am expecting is while sending Post request parameters should not get encoded.
Can someone please provide solution
I am assuming that you are trying to correlate the variable in the body of the subsequent request(2nd Request).
Try sending the data in "Body Data" instead of parameters. So, it is your variable i.e ${viewState} in "Body Data"
I hope view state is not in the URL.
Hope this helps.

finding content-type from wireshark

Here are the wireshark logs of 3 POST's. All posting the same data but with different content-types, resulting in different ways the data is read on the server. I'm attempt to to understand how to create POST Z.
POST X
Explicitly setting form based post
gives
POST Y
Omitted content-type
gives
POST Z ?
My app is not able to reproduce this.
gives
I'm attempting to guess what content-type in the last POST Z (notice there are no brackets), which made the post parameters appear as data ( and apparently without a data-type )
Thanks
~B
I'm attempting to guess what content-type in the last POST Z (notice there are no brackets), which made the post parameters appear as data ( and apparently without a data-type )
The content type is probably "none".
You're not obliged to send a Content-Type: header with a POST request. The HTTP 1.1 spec, RFC 2616, says in section 7.2.1 "Type":
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, therecipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".
It says SHOULD, not MUST, so a sender is allowed to send an entity-body without a Content-Type: header.

How to check if a couchdb document exists (without retrieving it)?

How can I just check if a document exists, mabye get the revision, but not make couchdb send the body of the document?
I remember I saw this explained somewhere but I cannot find it.
Edit: Iirc in the example you received only a http header with no data. The header indicated if present or not.
Edit2: Evan suggests to make a HEAD request (instead of GET). This answers my question.
CouchDB sends an ETag Header for document requests. The ETag Header is simply the document's revision in quotes.
Quoted from: http://wiki.apache.org/couchdb/HTTP_Document_API#ETags.2BAC8-Caching
Instead of performing a HTTP GET request, do a HTTP HEAD request. This will only return the headers and no content. The returned status will tell you if the object exists.

Resources