Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I know there are many questions like this in the forum, but I can't find a solution even by reading them. I'm new to Talend and I want to retrieve the values of the "id" and "userUID" fields from a list of accounts via an API call.
I'm using tRestClient and tExtractJSONFields and it works well. Now I need to iterate the "userUID" for get the details of all the accounts toghether, and I'm not able.
I used tFlowTolterate after the tExtractJSONFields but I'm not sure about the next steps. I saw someone using a tSetGlobalVar but I'm not sure it's the right way to reach the goal.
Anyone can help me?
The calls structure are:
[
{
"fullname": "xxxx",
"created_at": "2023-07-19T15:39:33+02:00",
"id": "64b7e795e39ee10dd656582622d",
"userUID": 54661010
},
{
"fullname": "yyy",
"created_at": "2023-07-19T15:39:33+02:00",
"id": "64b7e79yyyye10dd656582622d",
"userUID": 54667860
}
]{
"count": 3,
"addresses": [
{
"id": "65c0f1b75fb8e049f7dcd5dc",
"fullname": "xxxx",
"address": "Via skjhdf",
"hidden": false
},
{
"id": "65c9d7465fb8e004ac2ccdad",
"fullname": "xxxx",
"address": "Via aretrtrdh",
"hidden": false
},
{
"id": "65c9d7465fb8e004ac2ccdad",
"fullname": "xxxx",
"address": "Via ajdhdthdhh",
"hidden": false
}
]
}
Hi
As tRestClient doesn't accept 'Iterate' connector, add a tJava between tFlowToIterate and tRestClient, link tRestClient with 'OnComponentOK' from tJava.
...tExtractJsonField--main(row1)--tFlowToIterate--iterate--tJava--oncomponentok--tRestClient_2
on tRestCient_2, you can access the current 'id' or 'userUID' value with expression:
(String)globalMap.get("row1.id")
(String)globalMap.get("row1.userUID")
Hope it helps you.
Regards
Shicong
Hi
As tRestClient doesn't accept 'Iterate' connector, add a tJava between tFlowToIterate and tRestClient, link tRestClient with 'OnComponentOK' from tJava.
...tExtractJsonField--main(row1)--tFlowToIterate--iterate--tJava--oncomponentok--tRestClient_2
on tRestCient_2, you can access the current 'id' or 'userUID' value with expression:
(String)globalMap.get("row1.id")
(String)globalMap.get("row1.userUID")
Hope it helps you.
Regards
Shicong
Hi @Shicong_Hong and thank you for your reply. The schema now is:
I changed the schema because before all I load the data in a SQL Server table. Inside I have all the informations: id, userUID and others.
If I run the job I receive this error message: Exception in component tRESTClient_1 (GetShipmentDetails)
javax.ws.rs.BadRequestException: HTTP 400 Bad Request
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)...
The url of the tRestClient_1 is: "yyyyyyy.json?uid="+(String)globalMap.get("row1.userUID") but I'm sure it's wrong.
The other strange thing is that if I put a tLogRow after tJava_1 I get only so many in response:
I
I
I
I
...
As if in fact the interaction is not going well.
What you can suggest me?
Hi
Make sure the global variable (String)globalMap.get("row1.userUID") has value, print its value before it is used on tJava. To test if the URL works, type in a fixed value in the url, eg: "...yyyyyyy.json?uid=balabala", if it works, then change the url to use global variable.
The tJava component is only a helper construct to be able to trigger a component (which does not accept an Iterate trigger input) based on an Iterate trigger. The tJava has nothing to do and will not do anything. The only reason to add it is to convert an Iterate trigger into a OnComponentOk trigger wich is accepted by the tRESTClient component.
Actually I mostly use this construct because it has the additional advantage of separating the flows.
If you get empty values in your list, then your settings for the Json parsing are wrong.
I would print the response to get an exact knowledge about the document structure.
Please check also of you use the string output type of the tRestClient.