Are you working as a Data Engineer, and have you started using Talend? Maybe in one of your projects, you need to retrieve data from a REST API and process it inside Talend. The primary objective is to connect to the API, verify the request’s success, and extract specific fields from the JSON response.
Talend provides built-in components that simplify this process, such as tRestClient for calling APIs and tExtractJSONFields for parsing JSON.
A REST API is a service that allows applications to exchange information. When you request data from it, the API sends back a response, often in JSON format, which is structured as key-value pairs and is easy to process.
→ APIs offer different operations as follows:
→ GET – to retrieve data
→ POST – to send new data
→ PUT/PATCH – to update existing data
→ DELETE – to remove data
In this article, we will use GET because we only need to read data.
The tRestClient component is responsible for sending the request and capturing the response.
1. Drag tRestClient into your Talend job.
2. In Basic Settings, configure:
→ Endpoint: the path to the resource you want to access (in our case, a dummy API returning a sample JSON).
→ Method: GET.
→ Accept Type: application/json to request JSON as the response format.
3. (Optional) Add any necessary headers. For example, authentication or custom request parameters.
4. Link tRestClient to tLogRow temporarily to check the raw output.
The tRestClient provides:
statusCode – The response status (e.g., 200 for success, 404 for not found)
body – The actual JSON content returned
The API returns JSON data, but often it contains many fields we don’t need. We use tExtractJSONFields to parse the response and select only what’s relevant.
1. Add tExtractJSONFields and connect it to tRestClient.
2. In Basic Settings:
JSON field: choose the column containing the API’s JSON response.
Loop JSONPath query: $ (this means starting from the root of the JSON).
Mapping: define the fields you want, for example:
→ $.firstName
→ $.lastName
→ $.address.city
3. Assign a data type to each field:
→ String for text
→ Integer for numbers
→ Date for date fields
To visualise the results, link tExtractJSONFields to tLogRow and set display mode to Table for better readability.
For error handling, we suggest you use the error output from tRestClient to capture and log any failed calls. This allows you to store details like the error message and code for debugging.
→ tRestClient can connect to the API and retrieve JSON data.
→ tExtractJSONFields parses JSON starting from $ and extracts only the required fields.
→ tLogRow is the one who displays the clean output in table format.
→ Error flow is responsible for logging API request issues.
Watch the video tutorial here:
This is what happens when you run the job:
→ A successful call will show statusCode 200.
→ The parsed fields will appear neatly in the console.
→ If the call fails, the error details will be recorded.
In conclusion, retrieving data from a REST API and processing it inside Talend it’s an easy job. The primary objective is to connect to the API, verify the request’s success, and extract specific fields from the JSON response.
About btProvider:
We hold all possible technical and sales certifications for all products:
Talend, Tableau Desktop, Tableau Public, Tableau Server, Tableau Prep, Tableau Data Management, Vertica, Salesforce, Mulesoft, Write-Back.
With Talend – the best data management platform – you can always understand your data better. Using Talend, you will make intelligent and strategic decisions and seamlessly integrate, assure quality, and govern your data effortlessly. See other #skillpill video tutorials here:
Using measure names in parameter actions
Are you interested in learning more about Talend – the catalyst for efficient and comprehensive data management solutions across your company?
💡 Unlock the Power of Tableau for Smarter Data Decisions Are you ready to transform the way you see and use data? Tableau is more than just a data visualisation tool, it’s your gateway to interactive, intuitive, and impactful business […]
You are working at a Data Analytics company, and in one of your projects, you need to load data from a source into a target table using Talend. However, while running the Talend Job, the data will fail to load […]
In this Skillpill, you will learn how to use tSendMail in Talend. tSendMail is a component used to send emails directly from a Talend job. It supports various email protocols, such as SMTP, and allows the configuration of the sender, […]