Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Send session cookies along with a Rest API POST call

Hi,
I need to make a call to a Rest API which needs a cookie to be sent along with the header parameters. I was able to get the cookie using the tFileFetch component, but I am unable to set the cookies and make the second call to the ResT API. I need to send a Json object as an input parameter to the call.
I read on the couple of forums that i can set the cookies as header parameter in the advanced settings tab of a tRestClient, but I was not successful with it (may be I did not do it the right way).
Any help would be highly appreciated.
Thanks,
Dhruv
Labels (4)
5 Replies
Anonymous
Not applicable
Author

Hi Dhruv,
Have you already checked component reference with scenarios TalendHelpCenter:tRESTClient?
Best regards
Sabrina
Anonymous
Not applicable
Author

Hi Sabrina,
Yes, I did check the component reference guide but I couldn't find a solution to my problem. I know we can pass cookies as header parameters from the Advanced Setting tab but the component does not allow me to read the cookies which tFileFetch component created, right or I am missing something here. I used a work worked around for this, I made the first Rest call using a Java class in the routines and extracted the cookies it saved. I then used the cookie values and passed them as header parameters in the tRestClient call. If there is a better way to do this?
Thanks,
Dhruv
Anonymous
Not applicable
Author

Follow below process. 1) Pass the credential to the string column of the 1st tRestClient (login page). 2) Capture the cookie using "((java.util.Map>)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").get(1)" 3) In 2nd tRestClient component go to advance properties and add the below header properties. Name Value "Cookies" ((java.util.Map>)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").get(1) you should be able to connect using above process

MPande1611660090
Contributor
Contributor

Thanks. It helped, just one mistake it is "Cookie" not "Cookies".

powerchip
Contributor
Contributor

Thanks, in my case y have multiple cookies

 

//Get Cookie

//System.out.println(((java.util.Map)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie"));

//System.out.println(((java.util.Map)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").toString().replace("[","").replace("]","").replace(",",";").replace(";","\n"));

String str[] = ((java.util.Map)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").toString().replace("[","").replace("]","").replace(",",";").split("; ");

//System.out.println(str.length);

String out = "";

for(int index = 0; index < str.length; index++){

//System.out.println(str[index]);

if(str[index].startsWith("ABC") || str[index].startsWith("DEF")){

out = out + str[index] + ";";

}

}

output_row.cookie = out;