Create an Order

Learn how to create a draft order and adding items to it as a retailer.

Overview

This guide describes how to create an order and add order items. An order is a retailer’s request to purchase one or more products from an integrated supplier. An order is created when a customer completes the checkout process.

Orders can also be created through the API, after an order is created you can add additional order items, change the status of the order and change a few of its attributes using the API.


1. Set up ordering API

Follow the steps listed here for access to the Ordering API from your application. Once completed, you should receive an access token which you can use below $LIGHTSPEED_API_TOKEN


2. Connect to supplier

Before ordering from a supplier, you must first establish a connection with a supplier.

curl --location --request POST 'https://lsapi-supplier-orders.lightspeedappstg.com/suppliers/relations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $LIGHTSPEED_API_TOKEN' \
--data-raw '{
	"supplierID":"6229f891-d8d6-450d-8dd4-0a91f4baefad",
  "contactEmail":"[email protected]"
}'
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://lsapi-supplier-orders.lightspeedappstg.com/suppliers/relations"
  method := "GET"
  bearer := "<BEARER_TOKEN>"

  payload := strings.NewReader("{\n	\"supplierID\":\"6229f891-d8d6-450d-8dd4-0a91f4baefad\",\n	\"contactEmail\":\"[email protected]\"\n}")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("Authorization", bearer)

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}

This returns a Relation object:

{
  "id": "7deb2267-ed52-4bf9-a364-353a63d8e9d0",
  "supplierID": "6229f891-d8d6-450d-8dd4-0a91f4baefad",
  "retailerID": "7deb2267-ed52-4bf9-a364-353a63d8e9d0",
  "status": "Pending"
}

After creating the relationship, store the id value in your database so you can use it later. For example, the next step uses the id to create an order.

🚧

The relationship must be approved by the supplier before proceeding to step 3.


3. Create the order

Creating orders using the API requires an Order object and at least one order item. When you create the order, the status will be automatically set to OrderOpened.

# Using the supplier relation ID returned in step 2

curl --location --request POST 'https://lsapi-supplier-orders.lightspeedappstg.com/orders' \
--header 'Content-Type: application/json' \
--data-raw '{
    "supplierRelationID": "91de599d-0bdb-11ea-b62a-e2a56385c802",
    "orderedItems": [
        {
            "productID": "35ef9dea-f73d-11e9-80f3-d7e78880ed20",
            "quantity": 5
        }
    ]
}'

This returns a Order object with nested OrderItem objects:

{
  "createdBy": "280981",
  "createdDate": "2020-02-11 22:11:24",
  "id": "70fe4392-4d1b-11ea-81e8-ba88c8889bb5",
  "modifiedDate": "2020-02-11 22:11:24",
  "orderDate": null,
  "orderDeliveries": null,
  "orderStatus": "OrderOpened",
  "orderedItems": [
    {
      "id": "70fe43ed-4d1b-11ea-81e8-ba88c8889bb5",
      "productID": "35ef9dea-f73d-11e9-80f3-d7e78880ed20",
      "orderID": "70fe4392-4d1b-11ea-81e8-ba88c8889bb5",
      "status": "OrderItemOpened",
      "quantity": 5,
      "received": 0,
      "cost": 10.50,
      "totalCost": 52.5,
      "createdBy": "280981",
      "createdDate": "2020-02-11 22:11:24",
      "modifiedDate": "2020-02-11 22:11:24"
    }
  ],
  "otherCost": null,
  "percentageDiscount": null,
  "publicNote": null,
  "reference": null,
  "retailerNote": null,
  "shippingCost": null,
  "subtotal": 52.5,
  "supplierRelationID": "91de599d-0bdb-11ea-b62a-e2a56385c802",
  "totalCost": 52.5,
  "totalQuantity": 5
}

To view a line-by-line breakdown of a typical Order object please navigate HERE


(Optional) Order Notes

There are several ways to add notes to an order. These options allow you to add notes to your order so that they provide additional context.

When using the API, publicNote, retailerNote and supplierNote are automatically set to null. Alternatively, you can set these fields when either creating or modifying an order.}

View more information about Order Notes HERE


What’s Next

Congratulations! You’ve created an order on Lightspeed. Next, you might want to learn more about the ordering workflow or how to add shipments.