# REST API and CSV export - Stockpool 1.x documentation

> Read and change pools from an ERP, POS or stock system, export them as CSV, and be told when stock changes.

## REST API

Namespace `stockpool/v1`. Requests need a user with the **manage_woocommerce** capability (shop managers and administrators). WooCommerce REST API keys work too: create one under **WooCommerce → Settings → Advanced → REST API** and use it like for WooCommerce's own endpoints.

| Request | Does |
|---|---|
| `GET /wp-json/stockpool/v1/pools` | lists pools; `search`, `sku`, `per_page` (up to 500), `page`; totals in `X-WP-Total` and `X-WP-TotalPages` |
| `POST /pools` | creates a pool: `name` (required), `sku`, `stock`, `unit`, `low_stock`, `backorders` (`no`, `notify`, `yes`), `enabled` |
| `GET /pools/{id}` | one pool, plus `products`: every product using it, with `qty_per_unit` and `stock_status` |
| `PUT /pools/{id}` | changes the same fields; `stock` sets an exact count, logged as *REST API* |
| `DELETE /pools/{id}` | deletes the pool and its history |
| `POST /pools/{id}/adjust` | `change` (e.g. `-2.5`) adds or removes, or `stock` sets an exact count; optional `note` |
| `GET /pools/{id}/history` | the stock history, newest first: `change`, `stock_after`, `reason`, `order_id`, `note`, `user_id`, `date_gmt` |

Each pool comes back with `id`, `name`, `sku`, `unit`, `stock`, `low_stock`, `backorders`, `enabled` and `state` (`ok`, `low` or `out`).

```bash
# A delivery of 25 m, from a stock system.
curl -X POST https://example.com/wp-json/stockpool/v1/pools/12/adjust \
  -u ck_xxxxxxxx:cs_xxxxxxxx \
  -d change=25 -d note="Delivery 4471"
```

## Webhooks

The `stockpool_stock_changed` action fires after every stock change. It works as a WooCommerce webhook: under **WooCommerce → Settings → Advanced → Webhooks**, add one with the topic **Action** and the action `stockpool_stock_changed`. It sends the pool ID, the new and old stock, the reason and the order ID.

## CSV export

**Export CSV** on **Products → Shared stock** downloads every pool with the columns `id, name, sku, stock, unit, low_stock, backorders, enabled`. The file opens in Excel, Numbers or Google Sheets; it starts with a byte order mark so accents survive, and names that a spreadsheet would treat as a formula (starting with `=`, `+`, `-` or `@`) start with an apostrophe.

Source: https://extendiment.com/plugins/stockpool/docs/1.x/rest-api-and-csv
