# Sales orders

> Record what your customer ordered, deliver it with its delivery note, invoice what was delivered in one or several parts and know when it was paid.

A **sales order** (`sor_…`) is what your customer buys from you: the line items, their purchase order and when they expect it. You **deliver** it in one or several parts, each with its delivery note (`REM-1`, `REM-2`…), and **invoice** it in one or several invoices. Its status follows what happens on its own: `draft` → `confirmed` → `partially_delivered` → `delivered` → `invoiced` → `paid` (or `closed`, `canceled`). An order isn't a CFDI; each invoice that comes from it is.

## Create one

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/sales_orders \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_OufpKqnrvx9p42",
    "customer_po": "OC-778",
    "payment_form": "99",
    "payment_method": "PPD",
    "items": [
      { "description": "Silla de oficina ergonómica", "product_key": "56101504", "quantity": 100, "unit_price": 1850 }
    ],
    "expected_on": "2026-11-20",
    "payment_days": 30,
    "confirm": true
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const salesOrder = await fiscalisto.salesOrders.create({
  customer: "cus_OufpKqnrvx9p42",
  customer_po: "OC-778",
  payment_form: "99",
  payment_method: "PPD",
  items: [
    {
      description: "Silla de oficina ergonómica",
      product_key: "56101504",
      quantity: 100,
      unit_price: 1850,
    },
  ],
  expected_on: "2026-11-20",
  payment_days: 30,
  confirm: true,
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

sales_order = fiscalisto.sales_orders.create({
    "customer": "cus_OufpKqnrvx9p42",
    "customer_po": "OC-778",
    "payment_form": "99",
    "payment_method": "PPD",
    "items": [
        {
            "description": "Silla de oficina ergonómica",
            "product_key": "56101504",
            "quantity": 100,
            "unit_price": 1850,
        },
    ],
    "expected_on": "2026-11-20",
    "payment_days": 30,
    "confirm": True,
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$salesOrder = $fiscalisto->salesOrders->create([
    'customer' => 'cus_OufpKqnrvx9p42',
    'customer_po' => 'OC-778',
    'payment_form' => '99',
    'payment_method' => 'PPD',
    'items' => [
        [
            'description' => 'Silla de oficina ergonómica',
            'product_key' => '56101504',
            'quantity' => 100,
            'unit_price' => 1850,
        ],
    ],
    'expected_on' => '2026-11-20',
    'payment_days' => 30,
    'confirm' => true,
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	salesOrder, err := client.SalesOrders.Create(ctx, &fiscalisto.CreateSalesOrderParams{
		Customer:      fiscalisto.IDOf[fiscalisto.CreateSalesOrderParamsCustomer]("cus_OufpKqnrvx9p42"),
		CustomerPo:    fiscalisto.String("OC-778"),
		PaymentForm:   fiscalisto.String("99"),
		PaymentMethod: fiscalisto.String("PPD"),
		Items: []fiscalisto.CreateSalesOrderParamsItem{
			{
				Description: fiscalisto.String("Silla de oficina ergonómica"),
				ProductKey:  fiscalisto.String("56101504"),
				Quantity:    fiscalisto.Float64(100),
				UnitPrice:   fiscalisto.Float64(1850),
			},
		},
		ExpectedOn:  fiscalisto.String("2026-11-20"),
		PaymentDays: fiscalisto.Int64(30),
		Confirm:     fiscalisto.Bool(true),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(salesOrder.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateSalesOrderParams;
import com.fiscalisto.model.CreateSalesOrderParamsItem;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var salesOrder = fiscalisto.salesOrders().create(new CreateSalesOrderParams()
        .setCustomer("cus_OufpKqnrvx9p42")
        .setCustomerPo("OC-778")
        .setPaymentForm("99")
        .setPaymentMethod("PPD")
        .setItems(List.of(
                new CreateSalesOrderParamsItem()
                        .setDescription("Silla de oficina ergonómica")
                        .setProductKey("56101504")
                        .setQuantity(100)
                        .setUnitPrice(1850)
        ))
        .setExpectedOn("2026-11-20")
        .setPaymentDays(30)
        .setConfirm(true));
System.out.println(salesOrder.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var salesOrder = await fiscalisto.SalesOrders.CreateAsync(new CreateSalesOrderParams
{
    Customer = "cus_OufpKqnrvx9p42",
    CustomerPo = "OC-778",
    PaymentForm = "99",
    PaymentMethod = "PPD",
    Items = new()
    {
        new()
        {
            Description = "Silla de oficina ergonómica",
            ProductKey = "56101504",
            Quantity = 100,
            UnitPrice = 1850,
        },
    },
    ExpectedOn = "2026-11-20",
    PaymentDays = 30,
    Confirm = true,
});
```

The line items and payment terms are an [invoice's](https://fiscalisto.com/en/docs/api/facturas) and are checked with the same rules, so each invoice that comes from the order stamps. `customer` is a customer from your catalog (`cus_…`) or one with their tax data (added to your customers). With `"quote": "quo_…"` the order comes from a [quote](https://fiscalisto.com/en/docs/api/cotizaciones), with its customer and line items, and the quote is accepted.

Without `confirm` it stays a draft (`draft`) and changes with `POST /v1/sales_orders/{id}`; confirm it with `POST /v1/sales_orders/{id}/confirm`. Once confirmed, with [inventory](https://fiscalisto.com/en/docs/api/inventario) what was ordered is reserved in the warehouse and it can be delivered and invoiced.

`invoice_policy` says what gets invoiced: `delivered` (default), what's already delivered; `ordered`, everything ordered from the start (for example with prepayment). Services aren't delivered: they're invoiced from the first invoice.

## Deliver

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/sales_orders/sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx/deliveries \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [{ "line": 31, "quantity": 60 }],
    "carrier": "Paquetexpress",
    "tracking": "PX-90122"
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from 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",
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

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

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

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

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from 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"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(salesOrder.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateSalesOrderDeliveryParams;
import com.fiscalisto.model.CreateSalesOrderDeliveryParamsItem;
import java.util.List;

// The key comes from 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"));
System.out.println(salesOrder.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from 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",
});
```

`line` is the `id` of each line item in the order's `items`. Without `items`, everything still missing goes out. Goods leave the warehouse with the delivery, not with the invoice. If the issuer doesn't sell without stock, no more than there is goes out (`400 sales_order_invalid`). Each delivery carries its delivery note on the order's PDF and your customer signs it on their link; if you already know who received it, send it in `received_by`.

`POST /v1/sales_orders/{id}/deliveries/{dlv_…}/cancel` returns the goods to the warehouse. `POST /v1/sales_orders/{id}/cancel_remaining` leaves the order with what was already delivered.

## Invoice

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/sales_orders/sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx/invoice \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: PED-12-factura-1" \
  -d '{}'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const invoice = await fiscalisto.salesOrders.invoice("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", { idempotencyKey: "PED-12-factura-1" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

invoice = fiscalisto.sales_orders.invoice("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", idempotency_key="PED-12-factura-1")
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$invoice = $fiscalisto->salesOrders->invoice('sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx', [], ['idempotency_key' => 'PED-12-factura-1']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	invoice, err := client.SalesOrders.Invoice(ctx, "sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", nil, fiscalisto.WithIdempotencyKey("PED-12-factura-1"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = fiscalisto.salesOrders().invoice("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", null, RequestOptions.idempotencyKey("PED-12-factura-1"));
System.out.println(invoice.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var invoice = await fiscalisto.SalesOrders.InvoiceAsync("sor_OufpKqnrvx9p5Rt2mZr1XyT5uBcW8sKdLx", options: new RequestOptions { IdempotencyKey = "PED-12-factura-1" });
```

Stamps an invoice with what's delivered and not invoiced (or what `items` says), with the tax data the customer has in your catalog today and the note «Pedido PED-12 · Su orden de compra OC-778». It returns the invoice, like `POST /v1/invoices`. Each call with a new [Idempotency-Key](https://fiscalisto.com/en/docs/api/idempotencia) stamps the next part; repeating it with the same one returns the same invoice. If nothing is left to invoice, `400 sales_order_invalid`.

With `include_undelivered: true` it also invoices what isn't delivered yet. With `deliver: true`, stamping also records the delivery of what it carries (counter sale).

The order becomes `paid` when its invoices are paid: a PUE one when stamped, a PPD one with its [payment complements](https://fiscalisto.com/en/docs/api/pagos-y-notas-de-credito) or when the deposit is reconciled. `invoices` carries each invoice with what's left to pay (`balance`), and `paid_total` the sum paid. If you cancel an invoice, what it carried can be invoiced again.

## Send it to your customer

`POST /v1/sales_orders/{id}/send` emails it with its PDF and the link (`url`) where your customer confirms it, signs each delivery with «Ya lo recibí» (I received it), downloads their delivery notes and opens their invoices. With `"send_email": false` it only returns `url`. `GET /v1/sales_orders/{id}/pdf` gives the PDF.

## Events

| Event | When |
| --- | --- |
| `sales_order.confirmed` | It was confirmed (through the API or from the app). |
| `sales_order.customer_confirmed` | Your customer confirmed it on their link (`customer_confirmed_at`). |
| `sales_order.delivered` | Everything ordered has gone out (`delivered_at`). |
| `sales_order.paid` | Its invoices are paid (`paid_at`). |
| `sales_order.canceled` | It was cancelled (`cancel_reason`). |

## Close, cancel or reopen

| Route | What for |
| --- | --- |
| `POST /v1/sales_orders/{id}/close` | Marks it finished even if something is pending, and releases what was reserved. |
| `POST /v1/sales_orders/{id}/cancel` | Only without deliveries or stamped invoices. Deletes its draft invoices and releases what was reserved. |
| `POST /v1/sales_orders/{id}/reopen` | A closed or cancelled one is open again. |
| `DELETE /v1/sales_orders/{id}` | Deletes a draft. |

`close` and `cancel` accept `reason`, which stays in its history.
