> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keebai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GET /v1/ecommerce/products/:id/stock

> Read a product's stock per variant: the master total, what is allocated to branches, and what is left in the warehouse.

Returns where a product's stock is. Each variant carries its master total, how much of it is allocated to branches, and how much is still in the warehouse.

## Endpoint

```
GET https://api.keebai.com/v1/ecommerce/products/{id}/stock
```

## Required scope

`ecommerce:stock:read`

## Headers

| Header | Required | Value |
| - | - | - |
| `Authorization` | Yes | `Bearer kbai_pk_<token>` |

## Path parameters

| Field | Type | Required | Description |
| - | - | - | - |
| `id` | `string` | Yes | `ObjectId` of the product. |

## Example request

```bash curl theme={"system"}
curl https://api.keebai.com/v1/ecommerce/products/65d3e4f5a6b7c8d9e0f1a2b3/stock \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

```js JavaScript theme={"system"}
const response = await fetch(
  `https://api.keebai.com/v1/ecommerce/products/${productId}/stock`,
  { headers: { Authorization: `Bearer ${process.env.KEEBAI_API_TOKEN}` } },
);
const { variants } = await response.json();
```

```python Python theme={"system"}
import os, requests

resp = requests.get(
    f"https://api.keebai.com/v1/ecommerce/products/{product_id}/stock",
    headers={"Authorization": f"Bearer {os.environ['KEEBAI_API_TOKEN']}"},
    timeout=10,
)
resp.raise_for_status()
variants = resp.json()["variants"]
```

## Response

### 200 OK

```json theme={"system"}
{
  "product_id": "65d3e4f5a6b7c8d9e0f1a2b3",
  "variants": [
    {
      "variant_id": "65d3e4f5a6b7c8d9e0f1a2c1",
      "name": "42 / Negro",
      "total": 12,
      "allocated": 8,
      "warehouse_available": 4,
      "branches": [
        { "branch_id": "br_01", "quantity": 5 },
        { "branch_id": "br_02", "quantity": 3 }
      ]
    }
  ]
}
```

| Field | Type | Description |
| - | - | - |
| `product_id` | `string` | Same id you requested. |
| `variants[].variant_id` | `string` | `ObjectId` of the variant. |
| `variants[].name` | `string` | Variant name. |
| `variants[].total` | `number` | Master stock of the variant. |
| `variants[].allocated` | `number` | Part of the total assigned to branches. |
| `variants[].warehouse_available` | `number` | Part of the total still in the warehouse. |
| `variants[].branches` | `object[]` | Stock per branch: `branch_id` and `quantity`. |

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

The token does not have the `ecommerce:stock:read` scope.

### 404 Not Found

No product with that id, or it belongs to a different company.

### 502 Bad Gateway

`ECOMMERCE_UPSTREAM_ERROR` — the ecommerce service could not answer.

## Operational notes

* **`total` is the master stock.** Branch quantities are a split of it, not an addition: `allocated` is what sits in branches and `warehouse_available` is what is left.
* **The same shape comes back from writes.** [Adjusting](https://docs.keebai.com/dev/endpoints/ecommerce-stock-adjust.md) or [transferring](https://docs.keebai.com/dev/endpoints/ecommerce-stock-transfer.md) stock responds with this body, so you do not need a follow-up read.


## OpenAPI

````yaml GET /v1/ecommerce/products/{id}/stock
openapi: 3.0.0
info:
  title: Keebai Public API
  description: Superficie pública REST autenticada con Personal Access Tokens (PAT).
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.keebai.com
    description: Production
security: []
tags: []
paths:
  /v1/ecommerce/products/{id}/stock:
    get:
      tags:
        - ecommerce
      summary: Stock de un producto por variante y sucursal
      description: >-
        Por cada variante (o el producto, si no tiene variantes): stock total,
        lo asignado a sucursales, lo libre en bodega y el detalle por sucursal.
      operationId: PublicEcommerceOperationsController_getStock
      parameters:
        - name: id
          required: true
          in: path
          schema:
            type: string
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicProductStockDto'
      security:
        - PAT: []
components:
  schemas:
    PublicProductStockDto:
      type: object
      properties:
        product_id:
          type: string
        variants:
          type: array
          items:
            $ref: '#/components/schemas/PublicStockVariantDto'
      required:
        - product_id
        - variants
    PublicStockVariantDto:
      type: object
      properties:
        variant_id:
          type: string
          nullable: true
        name:
          type: string
        total:
          type: number
          description: Stock total
        allocated:
          type: number
          description: Unidades asignadas a sucursales
        warehouse_available:
          type: number
          description: Unidades libres en bodega
        branches:
          type: array
          items:
            $ref: '#/components/schemas/PublicStockBranchDto'
      required:
        - variant_id
        - name
        - total
        - allocated
        - warehouse_available
        - branches
    PublicStockBranchDto:
      type: object
      properties:
        branch_id:
          type: string
        quantity:
          type: number
      required:
        - branch_id
        - quantity
  securitySchemes:
    PAT:
      scheme: bearer
      bearerFormat: kbai_pk_<hex>
      type: http
      description: >-
        Personal Access Token con prefijo `kbai_pk_`. Generar desde el portal
        con permiso `developer.manage_tokens`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.