# Getting Started

Let's build a simple order fulfillment integration. When a new order is placed, it gets automatically sent to a fulfilment centre for processing, and then the order status is updated.

## Create a New Workflow

1. Click "New Workflow"
2. Name it "Order Fulfillment"

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyfSRRmLEurvKZJcO0Tg%2Fuploads%2FbKzWf6SHTmspiyNb9djX%2FCreate%20Workflow.mp4?alt=media&token=13eb8d7b-89a6-43d1-90ca-9e775f92935f>" %}

<details>

<summary>The workflow will receive as input order data in the following format (Click to expand)</summary>

<pre class="language-json" data-full-width="false"><code class="lang-json"><strong>{
</strong>  "id": 1,
  "orderNumber": "ORD-1751999768784",
  "customerName": "Sarah Johnson",
  "customerEmail": "sarah@example.com",
  "status": "pending",
  "total": "234.50",
  "shippingAddressLine1": "123 Main Street",
  "shippingAddressLine2": "Apt 4B",
  "shippingCity": "New York",
  "shippingState": "NY",
  "shippingZipCode": "10001",
  "shippingCountry": "US",
  "createdAt": "2025-01-08T18:36:08.000Z",
  "updatedAt": "2025-01-08T18:36:08.000Z",
  "items": [
    {
      "id": 1,
      "orderId": 1,
      "productId": 1,
      "quantity": 2,
      "price": "129.99",
      "product": {
        "id": 1,
        "name": "Wireless Earbuds Pro",
        "sku": "WEP-001",
        "category": "Electronics",
        "price": "129.99",
        "stock": 25,
        "status": "active",
        "description": "High-quality wireless earbuds",
        "imageUrl": "https://images.unsplash.com/photo-1572569511254-d8f925fe2cbb"
      }
    }
  ]
}
</code></pre>

</details>

## Adding Steps to Workflow

{% stepper %}
{% step %}

### Transforming incoming order data

First up, we'll need to create a new step to convert incoming order schema to fulfillment centre format.

{% tabs %}
{% tab title="Order Schema (Input)" %}

```json
{
  "id": 5,
  "orderNumber": "ORD-1752204924208",
  "customerName": "Lisa Chen",
  "customerEmail": "lisa.chen@email.com",
  "status": "pending",
  "total": "299.99",
  "shippingAddressLine1": "789 Oak Drive",
  "shippingAddressLine2": "Unit 5",
  "shippingCity": "Seattle",
  "shippingState": "WA",
  "shippingZipCode": "98101",
  "shippingCountry": "US",
  "trackingUrl": null,
  "shipmentReferenceId": null,
  "createdAt": "2025-07-11T03:35:24.196Z",
  "updatedAt": "2025-07-11T03:35:24.208Z",
  "items": [
    {
      "id": 9,
      "orderId": 5,
      "productId": 2,
      "quantity": 1,
      "price": 299.99,
      "product": {
        "id": 2,
        "name": "Smart Watch Series X",
        "sku": "SWX-002",
        "category": "Electronics",
        "price": 299.99,
        "stock": 12,
        "status": "active",
        "description": "Advanced smartwatch with health monitoring",
        "imageUrl": "https://images.unsplash.com/photo-1523275335684-37898b6baf30?ixlib=rb-4.0.3&auto=format&fit=crop&w=96&h=96",
        "createdAt": "2025-07-08T18:36:08.439Z",
        "updatedAt": "2025-07-08T18:36:08.446Z"
      }
    }
  ]
}
```

{% endtab %}

{% tab title="Order Schema (Fulfillment) " %}

```json
{
  "customer_name": "Lisa Chen",
  "customer_email": "lisa.chen@email.com",
  "customer_phone": "+1234567890",
  "shipping_address": {
    "street": "789 Oak Drive Unit 5",
    "city": "Seattle",
    "state": "WA",
    "zip": "98101",
    "country": "US"
  },
  "items": [
    {
      "sku": "SWX-002",
      "name": "Smart Watch Series X",
      "quantity": 1,
      "price": 299.99
    }
  ],
  "shipping_method": "standard"
}
```

{% endtab %}
{% endtabs %}

1. Click "Create New Step"
2. Name it "Transform incoming order data"
3. Select preferred language. For this tutorial, we will use Javascript
4. Click on the icon to select the step type. For this step, we'll keep `Data Transformation`&#x20;

Once the step is created, we can now start adding transformation logic to our step.

```javascript
(data) => {
    const inputOrder = data.input;

    // Use Array.map to transform the items array
    const transformedItems = inputOrder.items.map(item => ({
        sku: item.product.sku,
        name: item.product.name,
        quantity: item.quantity,
        price: parseFloat(item.price) // Convert price from string to number
    }));

    // Construct the final output object
    const outputOrder = {
        customer_name: inputOrder.customerName,
        customer_email: inputOrder.customerEmail,
        customer_phone: "+1234567890", // Placeholder as source data is missing
        shipping_address: {
            street: `${inputOrder.shippingAddressLine1 || ''} ${inputOrder.shippingAddressLine2 || ''}`.trim(),
            city: inputOrder.shippingCity,
            state: inputOrder.shippingState,
            zip: inputOrder.shippingZipCode,
            country: inputOrder.shippingCountry
        },
        items: transformedItems,
        shipping_method: "standard" // Default value as source data is missing
    };

    return outputOrder;
}
```

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyfSRRmLEurvKZJcO0Tg%2Fuploads%2Fp2S0V3JgC455vPad6eC4%2FTransform%20Incoming%20Order%20Data.mp4?alt=media&token=37427bf1-68ee-4475-8fec-00ec851c3cfa>" %}
{% endstep %}

{% step %}

### Send Order to Fulfillment Centre

Next up, we'll create a new step to send the transformed order data to the fulfillment centre via API.

1. Click "Create New Step"
2. Name it "Send Order to Fulfillment Centre"
3. Click on the icon to select the step type. For this step, we'll select `HTTP Request`&#x20;

We will then write logic for sending order data to fulfillment centre via HTTP Request.

```javascript
(data) => {
    // The body of the request is the output from the previous step (step_1)
    const requestBody = data.step_1.data;

    return {
        "lam.httpRequest": {
            "method": "POST",
            "url": "https://shipping-logistics-loic21.replit.app/api/orders",
            "headers": {
                "Content-Type": "application/json"
            },
            "body": requestBody
        }
    };
}
```

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyfSRRmLEurvKZJcO0Tg%2Fuploads%2FTWg8Av4nTdClHI4Kcyqg%2FSend%20order%20to%20fulfillment%20centre.mp4?alt=media&token=20f323cf-77f8-4c19-85c4-6232069cfcb7>" %}
{% endstep %}

{% step %}

### Update Order Status

Finally, we'll add a final step to update the order status.

1. Click "Create New Step"
2. Name it "Update order status"
3. Click on the icon to select the step type. For this step, we'll select `HTTP Request`&#x20;

We will add logic for updating order status via HTTP Request.

```javascript
(data) => {
    // Get the order ID from the initial workflow input
    const orderId = data.input.id;
    
    // Get the tracking URL and number from the response of the previous step (step_2)
    const tracking_url = data.step_2.response.tracking_url
    const tracking_number = data.step_2.response.tracking_number

    return {
        "lam.httpRequest": {
            "method": "PUT",
            "url": `https://order-track-pro-loic21.replit.app/api/orders/${orderId}`,
            "headers": {
                "Content-Type": "application/json"
            },
            "body": {
                "status": "Processing",
                "tracking_url": tracking_url,
                "shipment_reference_id": tracking_number,
            }
        }
    };
}
```

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyfSRRmLEurvKZJcO0Tg%2Fuploads%2F939wf3Z4yJMhCbIlWoiW%2FUpdate%20order%20status%20and%20tracking%20details.mp4?alt=media&token=e1f524e3-068f-46cd-9c29-de061d8bcd7d>" %}
{% endstep %}
{% endstepper %}

## Run your Workflow

We are now ready to test our workflow. We will be using the input below to run our workflow

* Provide Test Input (Use test input below)
* Click Run Workflow Button

<details>

<summary>Order Test Input (Click to expand)</summary>

```json
{
  "id": 5,
  "orderNumber": "ORD-1752204924208",
  "customerName": "Lisa Chen",
  "customerEmail": "lisa.chen@email.com",
  "status": "pending",
  "total": "299.99",
  "shippingAddressLine1": "789 Oak Drive",
  "shippingAddressLine2": "Unit 5",
  "shippingCity": "Seattle",
  "shippingState": "WA",
  "shippingZipCode": "98101",
  "shippingCountry": "US",
  "trackingUrl": null,
  "shipmentReferenceId": null,
  "createdAt": "2025-07-11T03:35:24.196Z",
  "updatedAt": "2025-07-11T03:35:24.208Z",
  "items": [
    {
      "id": 9,
      "orderId": 5,
      "productId": 2,
      "quantity": 1,
      "price": 299.99,
      "product": {
        "id": 2,
        "name": "Smart Watch Series X",
        "sku": "SWX-002",
        "category": "Electronics",
        "price": 299.99,
        "stock": 12,
        "status": "active",
        "description": "Advanced smartwatch with health monitoring",
        "imageUrl": "https://images.unsplash.com/photo-1523275335684-37898b6baf30?ixlib=rb-4.0.3&auto=format&fit=crop&w=96&h=96",
        "createdAt": "2025-07-08T18:36:08.439Z",
        "updatedAt": "2025-07-08T18:36:08.446Z"
      }
    }
  ]
}
```

</details>

After running your workflow, you'll see a new entry in the workflow executions section:

* **Overall Status**: Success or failure indicator
* **Step Results**: Individual step outputs and execution logs
* **Data Flow**: How data moved between steps
* **Execution Time**: Performance metrics for each step

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FeyfSRRmLEurvKZJcO0Tg%2Fuploads%2FmcMfr6ryy1VT4bVmiMp7%2FRun%20Workflow.mp4?alt=media&token=57571bd3-38fa-4fdb-a122-0a5ca446d014>" %}

Now that you've built your first workflow, let's dive deeper into creating more sophisticated integrations. Building effective workflows requires understanding how data flows between steps and mastering the different types of operations you can perform.
