Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I am trying ti use an API for the first time.
I have choosen a simple one and that seems public/open : http://restcountries.eu/
It's a list of countries with a lot of information https://restcountries.eu/rest/v2/all
In Talend 7.1 I designed a job with a tRestClient and then tExtractJSONfields ...
See all attachements.
When I run the job, I have compilation error...
Hi @DamienBlondel,
I have written a quick job to show you how to do this. I won't attach it as I think I am probably using a different version to you. But I will show you the screenshots for you to copy.
First of all, your job does not need to start with a tWarn. You can start it with the tRestClient component. You can see my job below...
When configuring the tRestClient, you were nearly there. But you need to remember to switch off the "Convert the response to DOM Document". This will wrap your JSON in an XML file.
I believe the above is the same as yours. The Advanced Settings is where you need to make your changes....
The last bit is the tExtractJSONFields component. The JSON you get from this API returns an array. So your loop needs to iterate over that array. I used this "$.[*]". This will allow you to focus on the components inside the array. Once you have that, you simply set JSONPaths to the components you want. I chose "name" ("$.name") and "alpha2Code" ("$.alpha2Code"). Notice that I chose "string" as the "JSON field". This is the column you need to use when dealing with JSON.
After this, I simply added a tLogRow which prints the output to the output window.
Hope this helps 🙂
The error seems to be link to this line of code
"row2.statusCode = webClientResponseStatus_tRESTClient_1;"
with associated message : StatusCode cannot be resolved or is not a field
Hi @DamienBlondel,
I have written a quick job to show you how to do this. I won't attach it as I think I am probably using a different version to you. But I will show you the screenshots for you to copy.
First of all, your job does not need to start with a tWarn. You can start it with the tRestClient component. You can see my job below...
When configuring the tRestClient, you were nearly there. But you need to remember to switch off the "Convert the response to DOM Document". This will wrap your JSON in an XML file.
I believe the above is the same as yours. The Advanced Settings is where you need to make your changes....
The last bit is the tExtractJSONFields component. The JSON you get from this API returns an array. So your loop needs to iterate over that array. I used this "$.[*]". This will allow you to focus on the components inside the array. Once you have that, you simply set JSONPaths to the components you want. I chose "name" ("$.name") and "alpha2Code" ("$.alpha2Code"). Notice that I chose "string" as the "JSON field". This is the column you need to use when dealing with JSON.
After this, I simply added a tLogRow which prints the output to the output window.
Hope this helps 🙂
Thank you for your help ...
I tried to update my initial job but it didn't work ...
I restarted from scratch following your exemple and it works !!!
Thank you very much.
Can you tell what is the role of the tlogRow in between the 2 main components ?
The tLogRow is a useful component for printing the values of the rows in the output window. However, you do not always want to have these switched on. It is useful to add tLogRows when developing and testing, but deactivate them when you no longer need them. This will not affect the flow of data. However, deactivating other components will affect the flow of data, so this technique is only for the tLogRow.