Order Products - Hands-on Lab

Lesson 23 of 26 · 30 min

In this lab, you will:

  • Create an order with a custom product
  • Add a product with options to an order
  • List order products

Prerequisites

  • BigCommerce store (sandbox or live)
  • Basic knowledge of APIs
  • REST client (Postman)

Create a Custom Order

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v2/orders
  1. Copy and paste the code below into the Body section of Postman
{
"products": [
{
"name": "Custom Product",
"price_inc_tax": 10.83,
"price_ex_tax": 10,
"sku": "123custom",
"quantity": 1
}
],
"billing_address": {
"first_name": "John",
"last_name": "Smith",
"company": "",
"street_1": "123 Main Street",
"street_2": "",
"city": "Austin",
"state": "Texas",
"zip": "78704",
"country": "United States",
"country_iso2": "US",
"phone": "5555555555",
"email": "jsmith@email.com"
},
"status_id": 11
}
  1. Select POST next to the request url
  2. Click the Send button
  3. Observe response

Add a Product with Options to an Order

  1. GET the option_values > id and option_values > option_id
  2. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v3/catalog/products/{product_id}/variants
  1. Replace {product_id} with the ID of a product in the store
  2. Make note of the option_values > id and option_values > option_id . These will be passed into the products array
  3. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v2/orders/{order_id}
  1. Replace {order_id} with the order ID to be updated
  2. Copy and paste the code below into the body section of Postman
{
"products": [
{
"product_id": {product_id},
"product_options": [
{
"id": {option_values > option_id},
"value": "{option_values > id}"
},
{
"id": {option_values > option_id},
"value": "{option_values > id}"
}
],
"quantity": 1
}
]
}
  1. Replace {product_id} with the ID of the product with option to be added to the order
  2. Replace {option_values > option_id} with the option ID retrieved previously
  3. Replace {option_values > id} with the option ID retrieved previously
  4. Select PUT next to the request url
  5. Click the Send button
  6. Observe response

List Order Products

  1. Copy and paste the request below into Postman
https://api.bigcommerce.com/stores/{{store_hash}}/v2/orders/{order_id}/products
  1. Replace {order_id} with the ID of an order
  2. Select GET next to the request url
  3. Click the Send button
  4. Observe response