# Record a delivery

`POST https://api.fiscalisto.com/v1/sales_orders/{id}/deliveries`

What went out, with its delivery note (REM-1, REM-2…): the goods leave the warehouse with the delivery, not with the invoice. By default, everything left. If the issuer doesn't sell without stock, no more than what there is goes out (400 sales_order_invalid). When everything has gone out sales_order.delivered arrives.

## Before you call

- **Sales orders 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 |
| --- | --- | --- | --- |
| `id` | path | yes | The object's id. |
| `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 |
| --- | --- | --- | --- |
| `items` | array of object |  | How much of each line item goes out. By default, everything left to deliver. (up to 200) |
| `items[].line` | integer | yes | The line item's id (items[].id). (greater than 0 and up to 9007199254740991) |
| `items[].quantity` | number | yes | Quantity (Cantidad). 1 by default. (greater than 0) |
| `delivered_on` | string |  | Today by default. |
| `carrier` | string |  | Carrier. (up to 120 characters) |
| `tracking` | string |  | Tracking number. (up to 120 characters) |
| `note` | string |  | A note on the delivery note. (up to 1000 characters) |
| `received_by` | string |  | Who received it, if you already know (if not, your customer signs it at url). (up to 120 characters) |

Example:

```json
{
  "items": [
    {
      "line": 31,
      "quantity": 60
    }
  ],
  "carrier": "Paquetexpress",
  "tracking": "PX-90122"
}
```

## With the TypeScript SDK

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

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

const salesOrder = await fiscalisto.salesOrders.deliver("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", {
  items: [{ line: 31, quantity: 60 }],
  carrier: "Paquetexpress",
  tracking: "PX-90122",
}, { idempotencyKey: "pedido-A-1042" });
```

## With the Python SDK

```python
from fiscalisto import Fiscalisto

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

sales_order = fiscalisto.sales_orders.deliver("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", {
    "items": [{"line": 31, "quantity": 60}],
    "carrier": "Paquetexpress",
    "tracking": "PX-90122",
}, idempotency_key="pedido-A-1042")
```

## With the PHP SDK

```php
<?php

use Fiscalisto\Fiscalisto;

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

$salesOrder = $fiscalisto->salesOrders->deliver('sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx', [
    'items' => [['line' => 31, 'quantity' => 60]],
    'carrier' => 'Paquetexpress',
    'tracking' => 'PX-90122',
], ['idempotency_key' => 'pedido-A-1042']);
```

## With the .NET SDK

```csharp
using Fiscalisto;

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

var salesOrder = await fiscalisto.SalesOrders.DeliverAsync("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", new CreateSalesOrderDeliveryParams
{
    Items = new() { new() { Line = 31, Quantity = 60 } },
    Carrier = "Paquetexpress",
    Tracking = "PX-90122",
}, 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()

	salesOrder, err := client.SalesOrders.Deliver(ctx, "sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", &fiscalisto.CreateSalesOrderDeliveryParams{
		Items: []fiscalisto.CreateSalesOrderDeliveryParamsItem{
			{Line: 31, Quantity: 60},
		},
		Carrier:  fiscalisto.String("Paquetexpress"),
		Tracking: fiscalisto.String("PX-90122"),
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(salesOrder.ID)
}
```

## With the Java SDK

```java
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.CreateSalesOrderDeliveryParams;
import com.fiscalisto.model.CreateSalesOrderDeliveryParamsItem;
import java.util.List;

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

var salesOrder = fiscalisto.salesOrders().deliver("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", new CreateSalesOrderDeliveryParams()
        .setItems(List.of(
                new CreateSalesOrderDeliveryParamsItem()
                        .setLine(31)
                        .setQuantity(60)
        ))
        .setCarrier("Paquetexpress")
        .setTracking("PX-90122"), RequestOptions.idempotencyKey("pedido-A-1042"));
System.out.println(salesOrder.getId());
```

## Response 201

OK.

A `SalesOrder` 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` | `"sales_order"` | yes | What kind of object it is («invoice», «customer»…). |
| `issuer` | string | yes | The issuer (iss_…). |
| `number` | string | yes | Its series and folio (PED-12). |
| `status` | `draft`, `confirmed`, `partially_delivered`, `delivered`, `invoiced`, `paid`, `closed`, `canceled` | yes | draft, confirmed, partially_delivered, delivered (all delivered), invoiced (all invoiced), paid (its invoices paid), closed (marked as finished) or canceled. It changes on its own, with what happens. |
| `stage` | string or null | yes | The business stage it is at («Por empacar», «En ruta»…), or null. Chosen in the app. |
| `url` | string or null | yes | The link where your customer views the order, confirms it, signs each delivery and opens their invoices. null while it is a draft or hasn't been sent. |
| `customer` | object | yes | The customer: their RFC, name, email and their id in your catalog. |
| `customer.tax_id` | string or null | yes | RFC (Rfc), 12 characters for a persona moral and 13 for a persona física. |
| `customer.name` | string or null | yes | Name. |
| `customer.email` | string or null | yes | Email to send it to (several separated by commas). Only used if sending is requested. |
| `customer.catalog_id` | string or null | yes | The customer (cus_…) in your catalog, or null if they aren't in it. |
| `customer_po` | string or null | yes | Your customer's purchase order number, or null. |
| `quote` | string or null | yes | The quote (quo_…) it came from, or null. |
| `currency` | string | yes | The currency. |
| `items` | array of object | yes | The line items: id (to deliver or invoice part of it), what was ordered, delivered, invoiced and what will no longer be delivered (canceled). goods is true when it leaves the warehouse. |
| `items[].id` | integer | yes | The line item's id in the order: with it you deliver or invoice part of it (line). (from -9007199254740991 to 9007199254740991) |
| `items[].description` | string | yes | Line item description (Descripcion), up to 1,000 characters. |
| `items[].product_key` | string or null | yes | Product or service key (ClaveProdServ), 8 digits from c_ClaveProdServ. Look it up with GET /v1/sat_catalogs/product_keys?q=… |
| `items[].quantity` | number | yes | Quantity (Cantidad). 1 by default. |
| `items[].unit` | string or null | yes | The unit, as the customer sees it. |
| `items[].unit_price` | number | yes | Unit price before taxes (ValorUnitario). |
| `items[].discount` | number | yes | The line item's discount, as an amount. |
| `items[].amount` | number | yes | The line item's amount, without taxes. |
| `items[].goods` | boolean | yes | true if it leaves the warehouse with each delivery; false if it is a service (only invoiced). |
| `items[].delivered` | number | yes | How much has already been delivered. |
| `items[].invoiced` | number | yes | How much has already been invoiced. |
| `items[].canceled` | number | yes | How much will no longer be delivered (POST /v1/sales_orders/{id}/cancel_remaining). |
| `subtotal` | number | yes | The subtotal, without taxes. |
| `total` | number | yes | The total with taxes. |
| `invoiced_total` | number | yes | The sum of its stamped invoices (without the canceled ones). |
| `paid_total` | number | yes | What has already been paid of those invoices. |
| `expected_on` | string or null | yes | The estimated delivery (YYYY-MM-DD), or null. |
| `payment_days` | integer | yes | Credit days: each invoice is due that many days after its date. (from -9007199254740991 to 9007199254740991) |
| `invoice_policy` | `delivered`, `ordered` | yes | delivered: each invoice carries what has been delivered; ordered: what was ordered is invoiced, delivered or not. |
| `ship_to` | string or null | yes | Where it is delivered, or null. |
| `terms` | string or null | yes | The terms printed on the order, or null. |
| `notes` | string or null | yes | The notes, like an invoice's. |
| `internal_note` | string or null | yes | The internal note (your customer doesn't see it), or null. |
| `deliveries` | array of object | yes | Its deliveries, each with its delivery note. |
| `deliveries[].id` | string | yes | Object identifier, with its prefix (iss_, inv_, ret_, cus_, prd_, emp_, bat_, brn_, whs_, stm_, adj_, evt_, whe_). |
| `deliveries[].object` | `"sales_order_delivery"` | yes | What kind of object it is («invoice», «customer»…). |
| `deliveries[].number` | string | yes | Its delivery note (REM-1). |
| `deliveries[].status` | `delivered`, `canceled` | yes | delivered, or canceled (the goods went back to the warehouse). |
| `deliveries[].delivered_on` | string | yes | The day it went out (YYYY-MM-DD). |
| `deliveries[].carrier` | string or null | yes | The carrier, or null. |
| `deliveries[].tracking` | string or null | yes | The tracking number, or null. |
| `deliveries[].note` | string or null | yes | A note, or null. |
| `deliveries[].received_by` | string or null | yes | Who received it (signed on the link or noted by you), or null. |
| `deliveries[].received_at` | string (date-time) or null | yes | When it was received, or null. |
| `deliveries[].items` | array of object | yes | How much of each line item went out (line is the order's items[].id). |
| `deliveries[].items[].line` | integer | yes | The order's line item (its items[].id). (from -9007199254740991 to 9007199254740991) |
| `deliveries[].items[].quantity` | number | yes | How much of it went out. |
| `deliveries[].created_at` | string (date-time) or null | yes | When it was recorded. |
| `invoices` | array of object | yes | Its stamped invoices (inv_…), with what is left to pay on each (balance). |
| `invoices[].id` | string | yes | Object identifier, with its prefix (iss_, inv_, ret_, cus_, prd_, emp_, bat_, brn_, whs_, stm_, adj_, evt_, whe_). |
| `invoices[].status` | `stamped`, `canceled` | yes | stamped, or canceled (what it carried can be invoiced again). |
| `invoices[].total` | number | yes | The invoice's total. |
| `invoices[].balance` | number or null | yes | What is left to pay on that invoice, or null if not known yet. |
| `customer_confirmed_at` | string (date-time) or null | yes | When your customer confirmed it on their link, or null. |
| `sent_at` | string (date-time) or null | yes | When it was sent, or null. |
| `viewed_at` | string (date-time) or null | yes | When your customer first opened the link, or null. |
| `confirmed_at` | string (date-time) or null | yes | When it was confirmed, or null. |
| `delivered_at` | string (date-time) or null | yes | When everything was delivered, or null. |
| `invoiced_at` | string (date-time) or null | yes | When everything was invoiced, or null. |
| `paid_at` | string (date-time) or null | yes | When its invoices were paid, or null. |
| `closed_at` | string (date-time) or null | yes | When it was closed, or null. |
| `canceled_at` | string (date-time) or null | yes | When it was canceled, or null. |
| `cancel_reason` | string or null | yes | Why it was canceled, or null. |
| `created_at` | string (date-time) or null | yes | When it was created. |

```json
{
  "id": "sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx",
  "object": "sales_order",
  "livemode": false,
  "issuer": "iss_OufpKqnrvx9p",
  "number": "PED-12",
  "status": "partially_delivered",
  "stage": "En ruta",
  "url": "https://fiscalisto.com/pedido/Rt2mZr1XyT5uBcW8sKdLx0VeNOufpKqnrvx9p5Rt2mZr1",
  "customer": {
    "tax_id": "ICV060329BY0",
    "name": "INMOBILIARIA CVA",
    "email": "compras@cva.example",
    "catalog_id": "cus_OufpKqnrvx9p42"
  },
  "customer_po": "OC-778",
  "quote": null,
  "currency": "MXN",
  "items": [
    {
      "id": 31,
      "description": "Silla de oficina ergonómica",
      "product_key": "56101504",
      "quantity": 100,
      "unit": "Pieza",
      "unit_price": 1850,
      "discount": 0,
      "amount": 185000,
      "goods": true,
      "delivered": 60,
      "invoiced": 60,
      "canceled": 0
    }
  ],
  "subtotal": 185000,
  "total": 214600,
  "invoiced_total": 128760,
  "paid_total": 0,
  "expected_on": "2026-11-20",
  "payment_days": 30,
  "invoice_policy": "delivered",
  "ship_to": "Av. Vallarta 1500, Guadalajara",
  "terms": "Entrega en dos partes.",
  "notes": null,
  "internal_note": null,
  "deliveries": [
    {
      "id": "dlv_OufpKqnrvx9p7",
      "object": "sales_order_delivery",
      "number": "REM-1",
      "status": "delivered",
      "delivered_on": "2026-11-10",
      "carrier": "Paquetexpress",
      "tracking": "PX-90122",
      "note": null,
      "received_by": "Laura Méndez",
      "received_at": "2026-11-10T13:20:00-06:00",
      "items": [
        {
          "line": 31,
          "quantity": 60
        }
      ],
      "created_at": "2026-11-10T09:05:00-06:00"
    }
  ],
  "invoices": [
    {
      "id": "inv_OufpKqnrvx9p9Qt6vB3nMc8xZl1kJh4gFd",
      "status": "stamped",
      "total": 128760,
      "balance": 128760
    }
  ],
  "customer_confirmed_at": "2026-11-04T17:42:00-06:00",
  "sent_at": "2026-11-04T10:15:00-06:00",
  "viewed_at": "2026-11-04T17:40:00-06:00",
  "confirmed_at": "2026-11-04T10:12:00-06:00",
  "delivered_at": null,
  "invoiced_at": null,
  "paid_at": null,
  "closed_at": null,
  "canceled_at": null,
  "cancel_reason": null,
  "created_at": "2026-11-04T10:05: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.
- `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.
- `resource_missing` (404): There's no object with that id (or it belongs to another issuer or the other mode).
- `sales_order_invalid` (400): The sales order couldn't be saved or can't do that in its current status (for example, nothing left to deliver or invoice, or it's canceled). `message_es` says why.

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