Simple Integration Example

Connecting two API endpoints together

Watch the demo

Video outline

In this video, we demonstrate how to build a simple integration using Laminar. We show you how to get data from a source, transform it, and send it to a destination.

Objective

To build a basic integration workflow using Laminar to get data from a source, transform it, and send it to a destination.

Key Steps

  1. Setting Up Workspace:

    • Sign up for Laminar and create a workspace.

  2. Creating Auth Credentials:

    • Create an Auth Credential for no authentication needed.

    • Create an Auth Credential with a bearer token for authentication to our Destination.

  3. Defining API Endpoints:

    • Define the source endpoint for data retrieval.

    • Define the destination endpoint for data transfer.

  4. Creating a Workflow:

    • Create a new workflow for getting and transforming data.

  5. Creating a Flow:

    • Add a flow within the workflow to specify source and destination.

  6. Executing the Workflow:

    • Run the workflow to see the data transformation and destination response.

  7. Transforming Data with JQ:

    • Use JQ to transform data within the flow.

    • Transform data to meet specific requirements (e.g., counting users, calculating averages).

  8. Executing Workflow via API Key:

    • Use an API key to execute the workflow externally.

    • Monitor the execution and response of the workflow.

Cautionary Notes:

  • Ensure correct API endpoints and credentials are used.

  • Double-check data transformations to avoid errors.

  • Monitor the workflow execution for any issues.

Tips for Efficiency:

  • Use descriptive names for API endpoints and credentials.

  • Test the workflow execution with sample data before full implementation.

  • Document any changes made to the workflow for future reference.

Data Transformation

We transformed our JSON using this JQ:

{
  "totalUsers": .unsortedData | length,
  "averageAge": (.unsortedData | map(.age) | add / length),
  "totalItemsSold": (.unsortedData | map(.items | map(.price) | add) | add),
  "users": (.unsortedData | map({name: .name, email: .email, totalSpent: (.items | map(.price) | add)}) | map(select(.totalSpent > 15)))
}
View the transformation log
2024-06-10 02:40:03,748 - INFO - Logging to lam_run_49_70_ec261cf3-7fd8-4602-a860-83b8db314423_20240610_024003.log
2024-06-10 02:40:03,749 - INFO - Running command with program file: /tmp/program13855931832107672971.lam, input: /tmp/input290028322661747570.json, workspace_id: 49, flow_id: 70, as_json: True
2024-06-10 02:40:03,749 - INFO - Processing input: /tmp/input290028322661747570.json
2024-06-10 02:40:03,750 - INFO - Parsing program file: /tmp/program13855931832107672971.lam
2024-06-10 02:40:03,750 - INFO - Event lam.run.start triggered, with properties: {'program_file': '/tmp/program13855931832107672971.lam', 'as_json': True, 'workspace_id': '49', 'flow_id': '70'}
2024-06-10 02:40:03,750 - INFO - Running jq script {
  "totalUsers": .unsortedData | length,
  "averageAge": (.unsortedData | map(.age) | add / length),
  "totalItemsSold": (.unsortedData | map(.items | map(.price) | add) | add),
  "users": ( .unsortedData | map({name: .name, email: .email, totalSpent: (.items | map(.price) | add)}) | map(select(.totalSpent > 15)))
} with input data {"renameKey":"renameValue","unsortedData":[{"id":1,"name":"Alice","age":35,"email":"alice@example.com","items":[{"name":"Widget","price":5},{"name":"Gadget","price":10},{"name":"Doodad","price":7}]},{"id":2,"name":"Bob","age":27,"email":"bob@example.com","items":[{"name":"Thing","price":8},{"name":"Stuff","price":12}]},{"id":3,"name":"Charlie","age":42,"email":"charlie@example.com","items":[{"name":"Whatchamacallit","price":15},{"name":"Doohickey","price":3},{"name":"Thingamajig","price":6}]},{"id":4,"name":"Dave","age":21,"email":"dave@example.com","items":[{"name":"Widget","price":5},{"name":"Gadget","price":10}]}]}
2024-06-10 02:40:03,784 - INFO - Handling jq output: {"totalUsers":4,"averageAge":31.25,"totalItemsSold":81,"users":[{"name":"Alice","email":"alice@example.com","totalSpent":22},{"name":"Bob","email":"bob@example.com","totalSpent":20},{"name":"Charlie","email":"charlie@example.com","totalSpent":24}]}

2024-06-10 02:40:03,785 - INFO - Event lam.run.success triggered, with properties: {'workspace_id': '49', 'flow_id': '70'}
2024-06-10 02:40:03,786 - INFO - Run complete, waiting for event logger to finish

Last updated