Enrich an API Response

How to use a first API response to enrich all items in a second API response's collection.

Working with incomplete data on a new software project costs companies time and money. Data integration projects involve data sources that can be difficult to access and use. Some of them require domain knowledge to even make sense out of their responses. Others fall short of delivering all the necessary information.

Use Xapix to enrich incomplete customer payments data using a map unit. Normalize a collection of international payment records to have a consistent currency using a transformation formula.

Steps
Steps
  1. Create or login to your Xapix account and import the Onboarding Exercises project template.

  2. On your onboarding exercise project’s home screen

    • click on the endpoint `GET /current_month_payments_eur`

    • select Edit Pipeline to get to your customer payments pipeline dashboard.

  3. Click Add Unit on the upper left corner. In the overlay dialogue, add the Connector unit named "exchangeratesapi.io latest" to the pipeline.

  4. Then, add a second Connector unit called "Internal Customer Payments DB" to the pipeline in the same way.

  5. Back on the pipeline dashboard, connect both connector units to the Request unit.

  6. Click Add Unit again and this time add a Map unit to the pipeline

  7. Using drag and drop, connect both your connectors to the Map unit and connect the Map unit to the endpoint.

  8. Now, click on the Map unit and

    • drag and drop the "body" attribute object into the Input collection field of the Map unit, so that the field "item" shows a data sample.

    • Unfold the "params" object by clicking on it

    • Drag and drop the "rates" object from exchangeratesapi.io connector’s body into a new "params" property.

    • Next, click on Inspect Sub Pipeline to create the map units transformations.

  9. The sub pipeline dashboard has all the features as the regular pipeline dashboard, allowing for complex data flows. For this exercise;

    • Connect the Entry unit with the Result unit.

    • Click on the Result unit and drag and drop over all four input attributes into new result properties.

    • Add another property called "amount_eur” of type literal and click “Set formula”.

    • In the formula editor add the item’s attribute “amount”, by typing or clicking, and type a slash for division.

    • Next, add the attribute “rate” from your params and type a square bracket for accessing a field inside the rates object.

    • Inside the brackets, add the item’s “currency” attribute to dynamically access the respective currency value.

  10. Click on the Endpoint unit and drag and drop the Map unit’s “result” attribute over into a new property.

  11. Use the Publish button to deploy your project.

  12. Test whether the response matches your expectations by copying the cURL command in the bottom right corner into a new terminal window on your computer.