# Adjust stock

`POST https://api.fiscalisto.com/v1/stock_adjustments`

Puts stock into or takes it out of a warehouse with its reason: the opening inventory, shrinkage, a theft, a surplus. Entries are valued at their unit_cost (or the average cost), exits at the issuer's cost (average or FIFO). The products must have track_stock: true. It's applied at once (status applied).

## Before you call

- **Advanced inventory in the plan** of your empresa, if your API account belongs to an empresa: it comes with Operaciones, which is added to any paid plan in **Ajustes › Plan y pagos** and comes in Corporativo. In test mode you can already use it.

## Parameters

| Name | In | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | header |  | Optional (the SDKs send it on their own). If the response is lost, repeat the request with the same value within 24 hours: it answers the same, with idempotent-replayed: true, and doesn't do it twice (it doesn't create, send emails or charge). |

## Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `issuer` | string |  | The issuer (iss_…). By default, your only issuer. |
| `warehouse` | string |  | The warehouse (whs_…). By default, the head office's. |
| `reason` | `shrinkage`, `theft`, `damage`, `expiration`, `internal_use`, `gift`, `initial`, `surplus`, `count`, `other` | yes | Why: shrinkage, theft (theft or loss), damage, expiration, internal_use, gift (sample or gift), initial (opening inventory), surplus, count (physical count) or other. |
| `note` | string or null |  | A note, for the kardex. |
| `lines` | array of object | yes | What comes in or goes out of each product, up to 500 lines. (up to 500) |
| `lines[].product` | string | yes | The product (prd_…), with track_stock: true. |
| `lines[].quantity` | number | yes | How much comes in (positive) or goes out (negative), in the product's unit. |
| `lines[].unit_cost` | number |  | What each unit coming in cost, in pesos without VAT; without it, today's average cost. (from 0) |
| `lines[].lot` | string |  | The lot or serial number, if the product carries them. (up to 60 characters) |
| `lines[].expires_on` | string |  | The expiration of a new lot (YYYY-MM-DD). |

Example:

```json
{
  "reason": "initial",
  "note": "Inventario de apertura",
  "lines": [
    {
      "product": "prd_OufpKqnrvx9p2",
      "quantity": 50,
      "unit_cost": 90
    }
  ]
}
```

## With the TypeScript SDK

```ts
import { Fiscalisto } from "fiscalisto";

// La llave viene de FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const stockAdjustment = await fiscalisto.stockAdjustments.create({
  reason: "initial",
  note: "Inventario de apertura",
  lines: [
    {
      product: "prd_OufpKqnrvx9p2",
      quantity: 50,
      unit_cost: 90,
    },
  ],
}, { idempotencyKey: "pedido-A-1042" });
```

## With the Python SDK

```python
from fiscalisto import Fiscalisto

# La llave viene de FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

stock_adjustment = fiscalisto.stock_adjustments.create({
    "reason": "initial",
    "note": "Inventario de apertura",
    "lines": [
        {
            "product": "prd_OufpKqnrvx9p2",
            "quantity": 50,
            "unit_cost": 90,
        },
    ],
}, idempotency_key="pedido-A-1042")
```

## With the PHP SDK

```php
<?php

use Fiscalisto\Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$stockAdjustment = $fiscalisto->stockAdjustments->create([
    'reason' => 'initial',
    'note' => 'Inventario de apertura',
    'lines' => [
        [
            'product' => 'prd_OufpKqnrvx9p2',
            'quantity' => 50,
            'unit_cost' => 90,
        ],
    ],
], ['idempotency_key' => 'pedido-A-1042']);
```

## With the .NET SDK

```csharp
using Fiscalisto;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockAdjustment = await fiscalisto.StockAdjustments.CreateAsync(new CreateStockAdjustmentParams
{
    Reason = "initial",
    Note = "Inventario de apertura",
    Lines = new()
    {
        new()
        {
            Product = "prd_OufpKqnrvx9p2",
            Quantity = 50,
            UnitCost = 90,
        },
    },
}, new RequestOptions { IdempotencyKey = "pedido-A-1042" });
```

## With the Go SDK

```go
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// La llave viene de FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	stockAdjustment, err := client.StockAdjustments.Create(ctx, &fiscalisto.CreateStockAdjustmentParams{
		Reason: "initial",
		Note:   fiscalisto.String("Inventario de apertura"),
		Lines: []fiscalisto.CreateStockAdjustmentParamsLine{
			{
				Product:  "prd_OufpKqnrvx9p2",
				Quantity: 50,
				UnitCost: fiscalisto.Float64(90),
			},
		},
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(stockAdjustment.ID)
}
```

## With the Java SDK

```java
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.CreateStockAdjustmentParams;
import com.fiscalisto.model.CreateStockAdjustmentParamsLine;
import java.util.List;

// La llave viene de FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var stockAdjustment = fiscalisto.stockAdjustments().create(new CreateStockAdjustmentParams()
        .setReason("initial")
        .setNote("Inventario de apertura")
        .setLines(List.of(
                new CreateStockAdjustmentParamsLine()
                        .setProduct("prd_OufpKqnrvx9p2")
                        .setQuantity(50)
                        .setUnitCost(90)
        )), RequestOptions.idempotencyKey("pedido-A-1042"));
System.out.println(stockAdjustment.getId());
```

## Response 201

OK.

A `StockAdjustment` object:

| Field | Type | Always present | Description |
| --- | --- | --- | --- |
| `id` | string | yes | Object identifier, with its prefix (iss_, inv_, ret_, cus_, prd_, emp_, bat_, brn_, whs_, stm_, adj_, evt_, whe_). |
| `livemode` | boolean | yes | true in production (fk_live_ keys), false in test mode (fk_test_). Test objects aren't valid before the SAT. |
| `object` | `"stock_adjustment"` | yes | What kind of object it is («invoice», «customer»…). |
| `issuer` | string | yes | The issuer. |
| `warehouse` | string | yes | The warehouse (whs_…). |
| `reason` | `shrinkage`, `theft`, `damage`, `expiration`, `internal_use`, `gift`, `initial`, `surplus`, `count`, `other` | yes | The reason (see POST /v1/stock_adjustments). |
| `note` | string or null | yes | Its note, or null. |
| `status` | `applied`, `pending`, `rejected`, `reversed` | yes | applied (it already moved stock), pending (awaiting approval in the app), rejected or reversed (it was undone). |
| `value` | number | yes | What what it moved is worth, in pesos without IVA. |
| `lines` | array of object | yes | What came in or went out of each product. |
| `lines[].product` | string | yes | A product from your catalog (prd_…): takes its key, unit, price and taxes. |
| `lines[].quantity` | number | yes | Quantity (Cantidad). 1 by default. |
| `lines[].unit_cost` | number or null | yes | The unit cost given to the adjustment, in pesos without IVA, or null (the average cost). |
| `lines[].lot` | string or null | yes | Medicine lot (LoteMedicamento). |
| `created_at` | string (date-time) or null | yes | When it was made. |

```json
{
  "id": "adj_OufpKqnrvx9p1",
  "object": "stock_adjustment",
  "livemode": false,
  "issuer": "iss_OufpKqnrvx9p",
  "warehouse": "whs_OufpKqnrvx9p1",
  "reason": "initial",
  "note": "Inventario de apertura",
  "status": "applied",
  "value": 4500,
  "lines": [
    {
      "product": "prd_OufpKqnrvx9p2",
      "quantity": 50,
      "unit_cost": 90,
      "lot": null
    }
  ],
  "created_at": "2026-10-27T09:30:00-06:00"
}
```

## Errors

- `feature_not_in_plan` (403): Live, this part of the API (inventario, portal de proveedores, pedidos, comprobación de gastos) follows the empresa's plan, as in the app: it comes with Operaciones (added to any paid plan; included in Corporativo). The books (the /v1/accounting routes except DIOT, cross checks, IVA refunds and fixed assets) come with Contabilidad (added to Independiente, Emprendedor or Negocio; included in Despacho and Corporativo): without it, changing the books answers this error, and reading them works only up to the last month it had it. Add either in Ajustes › Plan y pagos; test mode has everything.
- `inventory_refused` (400): Inventory doesn't allow it: the message says why (a lot that isn't that product's, another adjustment of the same warehouse in progress).
- `issuer_archived` (400): The issuer is archived and no longer stamps. Its documents can still be read and canceled.
- `issuer_linked_empresa` (403): That issuer is an empresa of the app connected to your account: through the API it only offers its Portal de proveedores (/v1/portal_suppliers and /v1/supplier_invoices) and, once someone who may pay suppliers and change Configurar pagos turned them on, its supplier payouts (/v1/payouts and /v1/payroll_payouts). It also stops when whoever connected it (or turned its payouts on) no longer has that permission in the empresa: message_es says which. Do everything else in the app.
- `issuer_missing` (404): There is no such issuer in the account (or it belongs to the other mode).
- `issuer_not_allowed` (403): This key can't use that issuer.
- `issuer_required` (400): The account has several issuers and the request doesn't say which: send `issuer` (iss_…).
- `livemode_mismatch` (400): The object belongs to the other mode: an fk_test_ key only sees test data and an fk_live_ key only live data.

Plus those of any call (key, fields, limits): https://fiscalisto.com/en/docs/api/errores.md.
