Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Call tRestClient with Post by passing Json body

Hello,

 

I am actually starting to learn Talend and I have this scenario: I need to call Rest WS, get the results, transform data so that it respect q certqin metadata Schema, then call another Rest Webservice, to post the data. What I used as components are : TRestClient -> tExtractJsonField ->TMap -> tRestWebservice. In the latest WS, I need :

- Send request one by one so should I use flowToIterate

- From the flow coming from the TMap, how can I prepare a Json body to send it in the Post of tRestClient.

 

I am getting an error / javax.ws.rs.WebApplicationException: HTTP 400 Bad Request 

 

talend-flow.PNG

Thanks 

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi 

 

So shall I go for this solution instead of using a txmlMap

 

Capturejson.PNG

View solution in original post

17 Replies
Anonymous
Not applicable
Author

Hi
tRestClient requries a document as input request, you need to use a tXMLMap instead of tMap to build the document. 

Or you can use tRest to call API and use tWriteJsonField to write a Json string and pass it to tRest.

Regards
Shong

Anonymous
Not applicable
Author

Hello Shong

 

Thanks for the reply. Ok let's assume that I will use the txmlMap. So the flow will be like this 

ws-with_txml.PNG

I am right? Now I still have javax.ws.rs.WebApplicationException: HTTP 400 Bad Request

NB: I am trying to send only one record. here my tXmlMap

ws-with_txml2.PNG

Anonymous
Not applicable
Author

Have you tried your API using Postman? Does it works? Can you show an example of Json string that are required as input request?
Anonymous
Not applicable
Author

Yes I have tried with postman. This is the body that I send postman.PNG

Anonymous
Not applicable
Author

The tXMLMap does not produce JSON. You need to send your JSON as a String to the tRestClient's "string" column. You also need to set the tRestClient up to receive JSON.

Anonymous
Not applicable
Author

Hi,

 

After using the tXMLMap, the output is as below


xml_output.PNG

 

How can I send it as Json String?

 

Anonymous
Not applicable
Author

Create JSON and do not use the tXMLMap.

Anonymous
Not applicable
Author

Hi 

 

So shall I go for this solution instead of using a txmlMap

 

Capturejson.PNG

Anonymous
Not applicable
Author

That would be a better approach if you want to produce JSON