Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Use a REST/JSON API from Talend ETL for the first time

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...

 

 

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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...

0683p000009M4gQ.png

 

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.

0683p000009M4sB.png

I believe the above is the same as yours. The Advanced Settings is where you need to make your changes....

0683p000009M57T.png

 

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.

0683p000009M57d.png

 

After this, I simply added a tLogRow which prints the output to the output window.

 

Hope this helps 🙂

View solution in original post

4 Replies
Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

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...

0683p000009M4gQ.png

 

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.

0683p000009M4sB.png

I believe the above is the same as yours. The Advanced Settings is where you need to make your changes....

0683p000009M57T.png

 

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.

0683p000009M57d.png

 

After this, I simply added a tLogRow which prints the output to the output window.

 

Hope this helps 🙂

Anonymous
Not applicable
Author

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 ?

Anonymous
Not applicable
Author

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.