O2M Logo
One to Many
Quick start
Was this page helpful?

Quick start

Make a key, read your warehouses, check a SKU and create an order.

Overview

This guide takes you from a new API key to your first order in O2M. You need a terminal with curl.

Make a key

Figure 2.1  Your keys in Settings → API and Webhooks → API keys, with the New key button at the top.
  1. 1Open Settings → API and Webhooks → API keys and click New key.
  2. 2Give it a name, such as the system that will use it, and tick what it may do. For this guide tick all of them.
  3. 3Copy the access key and the secret key.

Set your variables

The examples in these pages keep your keys in two variables, so no key is ever written into a command. Set them once in your terminal.

cURL
export O2M_ACCESS_KEY="<your access key>"
export O2M_SECRET_KEY="<your secret key>"

Check the key works

This request lists your warehouses. It changes nothing, so it is a safe first call.

cURL
curl "https://api.o2m.in/api/v1/warehouses" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY"
Response
{
  "warehouses": [
    {
      "id": "1",
      "code": "DEFAULT",
      "name": "Default warehouse",
      "kind": "own",
      "status": "active",
      "is_default": true,
      "fulfilment_mode": "external",
      "pincode": null
    }
  ]
}

A 401 means the key was not accepted: see Authentication.

Read the stock of a SKU

Replace MUG-BLUE with one of your SKUs. sellable is the number O2M offers to your sales channels.

cURL
curl "https://api.o2m.in/api/v1/stock/MUG-BLUE" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY"

Create an order

Use your own order number and a SKU that exists in O2M. O2M reserves the units at once.

cURL
curl -X POST "https://api.o2m.in/api/v1/orders" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-TEST-1" \
  -d '{
  "order_id": "TEST-1",
  "channel": "mysite",
  "lines": [
    {
      "sku": "MUG-BLUE",
      "quantity": 1,
      "unit_price": 100
    }
  ]
}'

The answer is 201 with the whole order. Keep its id: you need it to retrieve or cancel the order. Cancel this test order so its units go back on sale.

cURL
curl -X POST "https://api.o2m.in/api/v1/orders/<id>/cancel" \
  -H "X-Access-Key: $O2M_ACCESS_KEY" \
  -H "X-Secret-Key: $O2M_SECRET_KEY"

Next steps