# Quickstart

Path: `/guide/quickstart`
Summary: From zero to your first fulfilled order — one runnable walkthrough

This is the fastest path from nothing to a **fulfilled order** — the four setup calls,
then the outgoing happy path, glued into a single runnable script. Every request below
targets the environment selected in the header, so switch to **Onboarding / Staging**
before you run it.

> **TIP: Prefer a client?**
>
> Import the [Postman collection](/pulpo-wms.postman_collection.json) — it ships every
> endpoint with the `{{baseUrl}}` and `{{token}}` variables already wired up. Set those two
> collection variables and you can fire the calls below without writing any code.

## What you need first

- Credentials for a PULPO WMS user (you receive these during onboarding).
- One `warehouse_id` — you will read it in step 2.
- (3PL fulfillers: Your `merchant_id` and `merchant_channel_id`. As a 3PL these must match the product and customer on every order. / single merchants: Nothing extra — as a single merchant everything resolves to your default merchant and channel.)

## 1. Authenticate

Exchange credentials for a bearer token. It is valid for **60 minutes** — store it and
reuse it; do not re-authenticate per call.

**Endpoint: Authenticate or refresh an access token** — `POST /auth` (operationId: authenticate)

**Example (cURL):**

```bash
curl -X POST {{baseUrl}}/auth \
-H "Content-Type: application/json" \
-d '{ "grant_type": "password", "username": "you@example.com", "password": "••••••••" }'
```

**Example (Node.js):**

```js
const BASE = "{{baseUrl}}";

async function authenticate() {
const res = await fetch(BASE + "/auth", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    grant_type: "password",
    username: process.env.PULPO_USER,
    password: process.env.PULPO_PASSWORD,
  }),
});
if (!res.ok) throw new Error("auth failed: " + res.status);
const { access_token } = await res.json();
return access_token;
}
```

**Example (Python):**

```python
import os, requests

BASE = "{{baseUrl}}"

def authenticate():
  res = requests.post(f"{BASE}/auth", json={
      "grant_type": "password",
      "username": os.environ["PULPO_USER"],
      "password": os.environ["PULPO_PASSWORD"],
  })
  res.raise_for_status()
  return res.json()["access_token"]
```

## 2. Read your user and warehouses

Your user determines the Tenant you belong to and the Merchants you can manage. Warehouses
give you the `warehouse_id` every order is tied to.

**Endpoint: Get current user information** — `GET /iam/users/me` (operationId: getCurrentUser)

**Endpoint: List all warehouses** — `GET /warehouses/` (operationId: listWarehouses)

**Example (Node.js):**

```js
async function bootstrap(token) {
const auth = { Authorization: "Bearer " + token };
const me = await fetch(BASE + "/iam/users/me", { headers: auth }).then((r) => r.json());
const { warehouses } = await fetch(BASE + "/warehouses?limit=100&sort_by=id:asc", { headers: auth }).then((r) => r.json());
const warehouseId = warehouses[0].id;
return { me, warehouseId };
}
```

**Example (Python):**

```python
def bootstrap(token):
  auth = {"Authorization": f"Bearer {token}"}
  me = requests.get(f"{BASE}/iam/users/me", headers=auth).json()
  warehouses = requests.get(f"{BASE}/warehouses",
      params={"limit": 100, "sort_by": "id:asc"}, headers=auth).json()["warehouses"]
  return me, warehouses[0]["id"]
```

## 3. Subscribe to the events you care about

Register your HTTPS receiver once. For the outgoing flow, `packing_order_finished` (PIC)
and `sales_order_finished` (PGI) are the two that matter. See
[receiving webhooks](/guide/receiving-webhooks) for how to build the receiver correctly.

**Endpoint: Subscribe to webhook events** — `POST /webhook/` (operationId: subscribeWebhook)

**Example (cURL):**

```bash
curl -X POST {{baseUrl}}/webhook/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
  "url": "https://your-domain.com/webhooks/pulpo",
  "method": "POST",
  "warehouse_id": 140,
  "allowed_types": ["sales_order_created", "packing_order_finished", "sales_order_finished"]
}'
```

## 4. Create the customer, then the sales order

`third_party_id` is required — create the customer (`type: "C"`) first, then use the
returned `id` on the order. `priority` is also required; send `1` if you don't have a
use case for it.

**Endpoint: Create third parties in bulk** — `POST /iam/bulk/third_parties` (operationId: bulkCreateThirdParties)

**Endpoint: Create sales orders in bulk** — `POST /sales/bulk/orders` (operationId: bulkCreateSalesOrders)

**Example (Node.js):**

```js
async function createOrder(token, warehouseId) {
const auth = { Authorization: "Bearer " + token, "Content-Type": "application/json" };

const [customer] = await fetch(BASE + "/iam/bulk/third_parties", {
  method: "POST",
  headers: auth,
  body: JSON.stringify([{
    active: true,
    name: "Ada Lovelace",
    identifier_number: "SO-QUICKSTART-001-CUST",
    identifier_type: "ID",
    third_type: "C",
    // 3PL: also send merchant_id (+ merchant_channel_id) here.
  }]),
}).then((r) => r.json()).then((body) => body.created);

const res = await fetch(BASE + "/sales/bulk/orders", {
  method: "POST",
  headers: auth,
  body: JSON.stringify([{
    order_num: "SO-QUICKSTART-001",
    warehouse_id: warehouseId,
    third_party_id: customer.id,
    priority: 1,
    // 3PL: also send merchant_id + merchant_channel_id here.
    ship_to: { name: "Ada Lovelace", address: { street: "1 Analytical Way", city: "London", country_code: "826" } },
    items: [{ product_sku: "YOUR-SKU", quantity: 1 }],
  }]),
});
if (!res.ok) throw new Error("create failed: " + res.status + " " + (await res.text()));
return res.json();
}
```

**Example (Python):**

```python
def create_order(token, warehouse_id):
  auth = {"Authorization": f"Bearer {token}"}

  customer_res = requests.post(f"{BASE}/iam/bulk/third_parties", headers=auth, json=[{
      "active": True,
      "name": "Ada Lovelace",
      "identifier_number": "SO-QUICKSTART-001-CUST",
      "identifier_type": "ID",
      "third_type": "C",
      # 3PL: also send merchant_id (+ merchant_channel_id) here.
  }])
  customer_res.raise_for_status()
  customer_id = customer_res.json()["created"][0]["id"]

  res = requests.post(f"{BASE}/sales/bulk/orders", headers=auth, json=[{
      "order_num": "SO-QUICKSTART-001",
      "warehouse_id": warehouse_id,
      "third_party_id": customer_id,
      "priority": 1,
      # 3PL: also send merchant_id + merchant_channel_id here.
      "ship_to": {"name": "Ada Lovelace", "address": {"street": "1 Analytical Way", "city": "London", "country_code": "826"}},
      "items": [{"product_sku": "YOUR-SKU", "quantity": 1}],
  }])
  res.raise_for_status()
  return res.json()
```

> **NOTE: Response shape**
>
> Bulk create/update endpoints return `{"created": [{"id": ..., "order_num": ...}], "errors": {}}`
> (or `"updated"` for update endpoints) — not the full order. Fetch the full record with
> `GET /sales/orders/{id}` if you need it.

> **WARNING: order_num must be unique**
>
> Reusing an `order_num` is rejected. Derive it from your source system's order id so a
> safe retry sends the same value and never creates a duplicate — see
> [idempotency & retries](/guide/idempotency).

## 5. Follow it to completion

The warehouse picks and packs on the Android app. You will receive `packing_order_finished`
(PIC), then `sales_order_finished` (PGI) — at which point the order is fulfilled. If you
are not yet receiving webhooks, poll instead:

**Endpoint: Search sales orders** — `GET /sales/orders` (operationId: searchSalesOrders)

**Example (cURL):**

```bash
# Poll until state = ended (PGI)
curl "{{baseUrl}}/sales/orders?order_num=contains:SO-QUICKSTART-001&view_attributes=id,order_num,state" \
-H "Authorization: Bearer $TOKEN"
```

The `state` field walks `queue → picking → packing → shipping → ended`. The full picture —
including where the `paused` state actually lives — is on
[order states & lifecycles](/guide/order-states).

> **SUCCESS: That's the loop**
>
> Auth → warehouse → subscribe → create → observe. Every other flow (incoming, returns,
> transfers, kitting) is a variation on the same shape. Continue to the
> [incoming](/guide/incoming) and [outgoing](/guide/outgoing) happy paths for the details,
> and keep [best practices](/guide/best-practices) open while you build.

---

Website version: https://connect.pulpo.co/guide/quickstart
Whole guide in one file: https://connect.pulpo.co/llms-full.txt
Index of all pages: https://connect.pulpo.co/llms.txt
