Create a Job to extract data from an API and store it in a globalMap variable.
Procedure
-
In the Integration perspective, right-click the Job Designs node and
click Create Standard Job.
-
Enter a name, purpose and description for your Job, then click
Finish.
-
Add the following components to your design workspace and link them with connections:
- A tHttpRequest
- A tHMap
- A tLogRow
Your Job should look like this:
-
Double-click the tHttpRequest component and configure it
as follows:
Parameter |
Value |
URI |
"https://www.swapi.tech/api/people?page=1&limit=10" |
Method |
GET |
-
Double-click the tLogRow component and click the
... button next to Edit
schema.
-
Add the following columns in the input and copy them to the output, then click
OK.
Column |
Type |
pages |
Integer |
results |
Integer |
-
Double-click the tHMap component to generate the
map.
-
In the first step, select Select an existing hierarchical
mapper structure and click Next,
then select the structure you created from the API.
-
In the second step, keep the default option and click
Next, then click
Finish.
The map is created, you can now configure it.
-
Click the output row element and drag a
FixedLoop function in its Loop
tab.
-
Drag the input total_records element to the output
results element, and the input total_pages
to the output pages.
-
Click the output root element and open the
Util tab, then drag and drop a
PutValueToExternalMap function in it.
-
Drag and drop a Constant function on the
Key argument, double-click it and define the name of
the variable, total.pages for example.
-
Drag and drop an XPathFunction function on the
Value argument, double-click and enter
xs:integer(%v) in the
Function/Arguments field.
In this example, the variable created should be an Integer, however, the
PutValueToExternalMap produces a String by default.
In order to use the variable as an Integer, you need to add the
XPathFunction function to define it as a
BigInteger.
-
Drag and drop the input total_pages element on the
XPathFunction.
-
Save the map.
Results
The first part of the Job is configured, and you can run it to check the results. In
the next steps, you will use the variable in another component.