JSON Body for POST Method in tFileFetch Component

Highlighted
Six Stars

JSON Body for POST Method in tFileFetch Component

Hi there, 

 

I've been looking for an answer but the 2 topics I found had no solution.

So here is the problem :

 

I want to get a cookie session (with the tFileFetch comp.) from a web service to use it (the cookie session id) in a tRest component. The thing is there is no "Body HTTP" in the tFileFetch component where I could write my JSON, and when I use the parameter to write login and password I get an 400 error bad request, I really need to put my json into a Body http.

 

thanks


Accepted Solutions
Six Stars

Re: JSON Body for POST Method in tFileFetch Component

I found out a solution, thanks a lot for your help, I finally used a tJavaRow (tMap work also) -> tRestClient -> and used ((java.util.Map<String,java.util.List<String>>)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").get(0).toString() in the second tRest once I'm connected.

 

Thanks


All Replies
Nine Stars

Re: JSON Body for POST Method in tFileFetch Component

Why are you using tFileFetch to access the first web service?  Are you downloading a file, uploading a file, or both?  You can't specify the whole body of a POST request in tFileFetch as a string of JSON or otherwise.  The only time I am POSTing to a tFileFetch with JSON is when I am uploading a file and other parameters are needed.  I can use key/value parameters with a Content-type of application/x-www-form-urlencoded and this particular web service accepts them.

 

Are you sure you are putting your authentication credentials in the correct place in tFileFetch?  They could go in the 'Headers' section or the 'Advanced settings -> need authorization' section.  A 400 error is a bad request, most web services will return a 401 if authentication or authorization failed.  Make sure that you can access your web service outside of Talend in another environment such as Postman.

 

If you are not downloading or uploading files then consider using a tRestClient where you can specify the JSON body in the 'string' variable.

--
Please give Kudos and mark topics as solved where appropriate.
Six Stars

Re: JSON Body for POST Method in tFileFetch Component

Yes I can access to it in postman, and what I wanted to say, I need to GET what's call in postman in the "temporary header" -> JSESSIONID, which is temporary.

 

And I need to put a JSON in the body with a POST method. I can't use the need authorization section because I have other field to put in the body.

 

The main problem is how to get the cookie (JSESSIONID) when I need to put a string of JSON in the body to use my Web Service.

 

Sorry my english is not very well, I hope you'll understand everything clearly, thanks

Six Stars

Re: JSON Body for POST Method in tFileFetch Component

I found out a solution, thanks a lot for your help, I finally used a tJavaRow (tMap work also) -> tRestClient -> and used ((java.util.Map<String,java.util.List<String>>)globalMap.get("tRESTClient_1_HEADERS")).get("Set-Cookie").get(0).toString() in the second tRest once I'm connected.

 

Thanks

Nine Stars

Re: JSON Body for POST Method in tFileFetch Component

Great, I am glad you figured it out.  Please select one or more answers as solutions so this topic gets marked as solved.

--
Please give Kudos and mark topics as solved where appropriate.

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

An API-First Approach to Modernizing Applications

Learn how to use an API-First Approach to Modernize your Applications

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read