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)
17 Replies
Nordom_LH
Contributor
Contributor

Did you manage to sort out how to execute the trestclient?

 How do you pass all field from input row to a json document inside the body of the trestclient.

Could trestclient body allow to mapped expected field to pass from the current row?

Anonymous
Not applicable
Author

This is demonstrated in the solution image. If you read the rest of the post, the information is there.

Nordom_LH
Contributor
Contributor

Thanks for the hint, I have read the full post including image, I am still lost on what to do inside tmap and jsonwrite

Nordom_LH
Contributor
Contributor

I have sort it out: just need to put the loop in the first field int twritejsonfield,  check the remove root node and ensure trestclient is fully configured in json, I now have to understand why null are transformed in []

Anonymous
Not applicable
Author

Great news! I try to give enough information in my posts so that others can figure it out for themselves for similar issues. I find that you learn the product better if you have to struggle a little on your own 0683p000009MA9p.png

Nordom_LH
Contributor
Contributor

to fixe the null transformed [ ] : in Insert a tJavaRow with the following code right after your tWriteJsonField:

output_row.string = input_row.string.replaceAll(",?\"[a-zA-Z_0-9]*\":\\[\\]", "");

thanks to Jbalberge

initial post https://community.talend.com/t5/Design-and-Development/resolved-Empty-Null-fields-show-up-in-json-ou...

Anonymous
Not applicable
Author

In order to resolve the issue of Null array generated by the tWriteJsonField, yu need to declare the attribute as object and not String Like below

 

0683p000009M9d0.png

LuciusHunt
Contributor
Contributor

For me the following solution works:

tMap -> tWriteJSONField -> tRestClient

Here's the big picture:

0693p000009roibAAA.gif

Do not propagate schemas or retrieve schemas from a target component.

Especially not from the tRESTClient. This could destroy it's schemas and then you need to put a new one.