# Best practices

Path: `/guide/best-practices`

> **TIP: Prefer a client?**
>
> Import the [Postman collection](/pulpo-wms.postman_collection.json) — it ships every
> endpoint in this reference with the `{{baseUrl}}` and `{{token}}` variables already
> wired up.

## Pagination

Pulpo uses **offset-based** pagination. The mandatory elements are `limit` and `offset`;
this applies to almost all public endpoints.

*Diagram — offset pagination with limit=100: request Page 1 (offset 0), Page 2 (offset 100), Page 3 (offset 200) … keep advancing the offset until a page returns fewer rows than the limit.*

```
GET /sales/orders?limit=100&offset=100&capped_limit=0&sort_by=id:asc
```

| Parameter      | Details                                                                                                              |
| -------------- | -------------------------------------------------------------------------------------------------------------------- |
| `limit`        | 1–2000. Common values are 10 or 100. Larger pages mean bigger payloads and slower responses. Default 10.             |
| `offset`       | Records to skip. Default 0.                                                                                          |
| `sort_by`      | Order by an incremental field (e.g. `id`, `inserted_at`) so rows don't shift between pages.                          |
| `capped_limit` | Set to `0` to drop `total_results` and gain \~20% speed. You then paginate until you get fewer than `limit` records. |

> **WARNING: Never silently cap results**
>
> Don't hardcode a single `limit` and assume you fetched everything. Paginate until the page
> is short. With `capped_limit=0` and a stable `sort_by`, you also capture rows created during
> the pagination run.

## Filtering & view attributes

Filtering applies a boolean condition to reduce the collection server-side — fewer records,
faster responses.

- **`XXX_id`** — filter by an indexed id. For orders, always include `warehouse_id`:
  `GET /picking/orders?warehouse_id=121&limit=100&sort_by=id:asc`.
- **Date ranges** — `delivery_date`, `inserted_at`, `updated_at` with `between:`, `gte:`,
  `lte:` and `YYYY-MM-DD hh:mm:ss` format.
- **`state`** — e.g. `state=ended`, or a dynamic search with `__search` / `__or_search`.
- **`view_attributes`** — restrict which root-level fields the response returns, so you don't
  pull the full element back.

## Rate limits & throttling

Limits are **tenant-based** (not per user): the default tier ranges from **60** to **300**
calls per minute. Internal calls from the Pulpo frontend, wizard or Android app do not count.

**Endpoint: Handle 429 responses** — `HTTP/1.1 429 Too Many Requests`

```json
{
"message": "rate_limit_reached",
"retry_after_seconds": 1.0
}
```

- **Store the token** — reuse it for its 60-minute life.
- **Respect rate limits** — parallel requests won't speed things up; they burn your budget.
- **Batch your requests** — prefer bulk endpoints (`POST /inventory/bulk/products`).
  Recommended batch size: up to 50 items per request.
- **Check for misconfigurations** — avoid accidental loops or unnecessary requests.
- **Cache** cross-reference lookups (external code → Pulpo id) locally.
- **Queue** messages so a 429 pauses and retries after `retry_after_seconds` rather than
  losing requests.

---

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