# Clientes

> Las operaciones de Clientes de la API de Trevol: parámetros, cuerpo, respuestas y ejemplos de código.

Fuente: https://platform.trevol.si/docs/api/customers

El catálogo de clientes de la empresa (el mismo de la app y de la sincronización con la DIAN): crear, consultar, buscar, editar y desactivar; y facturar con `customer.id`.

Los ejemplos de código salen de los SDK reales. La llave va en `TREVOL_API_KEY`; los cuerpos de ejemplo son los de la especificación. Los errores comunes están en [Errores](/docs/errores).

## Crear un cliente

`POST /v1/customers` · `createCustomer`

Crea un cliente en el catálogo. Obligatorios: `document_type`, `document_number` (sin DV ni puntos) y `name`. El DV lo calcula Trevol (si mandas `check_digit`, tiene que ser el correcto); el departamento sale de `municipality_code`. Si ya hay uno con ese documento o `external_id` (activo o desactivado), 409 `duplicate_customer` con `existing_id` y `existing_active`: no se reactiva solo. `defaults` son las condiciones de venta del cliente: al facturar con `customer.id` se aplican las que la petición no trae (forma de pago y plazo, medio de pago; el correo del cliente si no mandas `customer.email`). El documento, el DV, el correo y el teléfono de los clientes son del permiso `customers:read` de la llave (se marca al crearla): sin él, cualquier llave los recibe en `null` con `personal_data: "redacted"`, y buscar por documento (`document_number`, o un `q` que es un número de documento) es 403 `permission_denied` con `required_permission: "customers:read"`. Lo mismo en TODO lo que devuelve la API a esa llave: el `customer` de las facturas, las notas y el documento equivalente (con su `qr`, que lleva el documento del cliente, y el correo de la entrega), la contraparte de lo emitido en `/v1/dian_documents` y la columna del documento en `/v1/reports/documents`; y un `duplicate_customer` por documento no dice cuál es (`existing_id`). Los archivos de un documento emitido con Trevol (`…/pdf`, `…/xml`, `…/zip`) son el documento fiscal y lo traen como se emitió. Cada empresa tiene dos catálogos, uno por ambiente, y la llave decide cuál usa: con una de producción (`tvl_live_`), el de producción (el mismo de la app, Clientes y Productos, y el que llena la sincronización con la DIAN); con una de prueba (`tvl_test_`), el de habilitación, aparte y vacío al comienzo. Un id del otro ambiente es 404, como uno que no existe. Crear exige una llave de escritura e `Idempotency-Key`; editar exige una llave de escritura. Las escrituras cuentan en el límite de lecturas (600 por minuto), no en el tope diario de documentos; las altas tienen su tope: 10.000 clientes y 10.000 productos nuevos al día por empresa y ambiente (429 `rate_limited` con `limit: "catalog_daily"`). No hay DELETE: se desactiva con `PATCH {"active": false}` y se reactiva con `{"active": true}`; uno desactivado no se puede facturar por id. Los cambios avisan por webhook (`customer.*`, `product.*`).

**Parámetros**

| Nombre | En | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | cabecera | texto | sí | Obligatoria: 1 a 255 caracteres ASCII visibles, única por pedido (7 días). |

**Cuerpo** ([CatalogCustomerInput](/docs/api/objetos#CatalogCustomerInput), obligatorio)

| Campo | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- |
| `document_type` | `11` \| `12` \| `13` \| `21` \| `22` \| `31` \| `41` \| `42` \| `47` \| `48` \| `50` \| `91` | sí | Tabla 13.2.1 de la DIAN: 13 CC, 31 NIT, 22 CE, 41 PA… |
| `document_number` | texto | sí | Sin DV ni puntos. 11, 12, 13, 31 y 91 solo llevan números. |
| `check_digit` | entero (puede ser null) |  | Opcional: si viene, tiene que ser el DV del NIT. Si no, lo calcula Trevol. |
| `name` | texto | sí |  |
| `trade_name` | texto (puede ser null) |  |  |
| `person_type` | `legal` \| `natural` \| `null` (puede ser null) |  |  |
| `tax_responsibilities` | lista de `R-99-PN` \| `O-13` \| `O-15` \| `O-23` \| `O-47` (puede ser null) |  | Tabla 13.2.6.1. R-99-PN (no responsable) no se combina con otras. Máximo 5. |
| `email` | texto (puede ser null) |  |  |
| `phone` | texto (puede ser null) |  |  |
| `address` | texto (puede ser null) |  |  |
| `city` | texto (puede ser null) |  |  |
| `municipality_code` | texto (puede ser null) |  | Código DANE del municipio (5 dígitos). El departamento sale de aquí. |
| `country` | texto (puede ser null) |  | ISO 3166-1 alfa-2. Por defecto CO. |
| `defaults` | decimal |  |  |
| `active` | booleano |  | false lo desactiva (no se puede facturar por id); true lo reactiva. |
| `external_id` | texto (puede ser null) |  | Tu id del registro (1 a 100 caracteres: letras, números y :._/-). Único por empresa; null lo borra. |

**Respuestas**

| Estado | Qué pasó |
| --- | --- |
| 201 | El cliente creado ([CatalogCustomer](/docs/api/objetos#CatalogCustomer)) |
| 409 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| 422 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| Error | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |

`POST /v1/customers` (`createCustomer`)

#### cURL

```bash
curl -X POST "https://api.trevol.si/v1/customers" \
  -H "Authorization: Bearer $TREVOL_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "external_id": "ERP-CLI-0042",
  "document_type": "31",
  "document_number": "900373427",
  "name": "DISTRIBUIDORA LOS ANDES SAS",
  "person_type": "legal",
  "tax_responsibilities": [
    "O-13"
  ],
  "email": "facturacion@distribuidoralosandes.example",
  "phone": "6045550142",
  "address": "Carrera 43A # 1-50, Oficina 302",
  "city": "Medellín",
  "municipality_code": "05001",
  "defaults": {
    "payment_form": "credit",
    "term_days": 30,
    "payment_method": "47",
    "withholding_agent": true
  }
}'
```

#### Node.js

```javascript
import { Trevol } from '@trevol/sdk';

const trevol = new Trevol(); // lee TREVOL_API_KEY

const resultado = await trevol.customers.createCustomer({
  catalogCustomerInput: {
    external_id: 'ERP-CLI-0042',
    document_type: '31',
    document_number: '900373427',
    name: 'DISTRIBUIDORA LOS ANDES SAS',
    person_type: 'legal',
    tax_responsibilities: ['O-13'],
    email: 'facturacion@distribuidoralosandes.example',
    phone: '6045550142',
    address: 'Carrera 43A # 1-50, Oficina 302',
    city: 'Medellín',
    municipality_code: '05001',
    defaults: {
      payment_form: 'credit',
      term_days: 30,
      payment_method: '47',
      withholding_agent: true
    }
  },
  // idempotencyKey: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
});
console.log(resultado);
```

#### Python

```python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.customers.create_customer(
    catalog_customer_input={
        "external_id": "ERP-CLI-0042",
        "document_type": "31",
        "document_number": "900373427",
        "name": "DISTRIBUIDORA LOS ANDES SAS",
        "person_type": "legal",
        "tax_responsibilities": ["O-13"],
        "email": "facturacion@distribuidoralosandes.example",
        "phone": "6045550142",
        "address": "Carrera 43A # 1-50, Oficina 302",
        "city": "Medellín",
        "municipality_code": "05001",
        "defaults": {
            "payment_form": "credit",
            "term_days": 30,
            "payment_method": "47",
            "withholding_agent": True,
        },
    },
    # idempotency_key="VENTA-2026-000123",  # opcional: si falta, el SDK pone una y la repite en los reintentos
)
print(resultado)
```

#### PHP

```php
<?php

use Trevol\Trevol;

require __DIR__ . '/vendor/autoload.php';

$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'

$resultado = $trevol->customers->createCustomer(
    catalog_customer_input: [
        'external_id' => 'ERP-CLI-0042',
        'document_type' => '31',
        'document_number' => '900373427',
        'name' => 'DISTRIBUIDORA LOS ANDES SAS',
        'person_type' => 'legal',
        'tax_responsibilities' => ['O-13'],
        'email' => 'facturacion@distribuidoralosandes.example',
        'phone' => '6045550142',
        'address' => 'Carrera 43A # 1-50, Oficina 302',
        'city' => 'Medellín',
        'municipality_code' => '05001',
        'defaults' => [
            'payment_form' => 'credit',
            'term_days' => 30,
            'payment_method' => '47',
            'withholding_agent' => true,
        ],
    ],
    // idempotency_key: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
);
echo $resultado, PHP_EOL;

```

#### Java

```java
import si.trevol.Trevol;
import si.trevol.generado.model.CatalogCustomerInput;

public class Ejemplo {
    public static void main(String[] args) throws Exception {
        Trevol trevol = Trevol.builder().apiKey(System.getenv("TREVOL_API_KEY")).build(); // tvl_test_… → trevol.environment() == TEST

        CatalogCustomerInput entrada = CatalogCustomerInput.fromJson("""
            {
              "external_id": "ERP-CLI-0042",
              "document_type": "31",
              "document_number": "900373427",
              "name": "DISTRIBUIDORA LOS ANDES SAS",
              "person_type": "legal",
              "tax_responsibilities": [
                "O-13"
              ],
              "email": "facturacion@distribuidoralosandes.example",
              "phone": "6045550142",
              "address": "Carrera 43A # 1-50, Oficina 302",
              "city": "Medellín",
              "municipality_code": "05001",
              "defaults": {
                "payment_form": "credit",
                "term_days": 30,
                "payment_method": "47",
                "withholding_agent": true
              }
            }
            """);
        var resultado = trevol.customers().createCustomer(entrada)
                // .idempotencyKey("VENTA-2026-000123") // opcional: si falta, el SDK pone una y la repite en los reintentos
                .execute();
        System.out.println(resultado);
    }
}

```

#### C#

```csharp
using System;
using System.Threading.Tasks;
using Trevol;
using Trevol.Generado.Model;

public static class Ejemplo
{
    public static async Task Main()
    {
        var trevol = new TrevolClient(Environment.GetEnvironmentVariable("TREVOL_API_KEY")); // tvl_test_… → trevol.Environment == TrevolEnvironment.Test

        var entrada = TrevolJson.Deserialize<CatalogCustomerInput>("""
            {
              "external_id": "ERP-CLI-0042",
              "document_type": "31",
              "document_number": "900373427",
              "name": "DISTRIBUIDORA LOS ANDES SAS",
              "person_type": "legal",
              "tax_responsibilities": [
                "O-13"
              ],
              "email": "facturacion@distribuidoralosandes.example",
              "phone": "6045550142",
              "address": "Carrera 43A # 1-50, Oficina 302",
              "city": "Medellín",
              "municipality_code": "05001",
              "defaults": {
                "payment_form": "credit",
                "term_days": 30,
                "payment_method": "47",
                "withholding_agent": true
              }
            }
            """);
        var resultado = await trevol.Customers.CreateCustomerAsync(
            catalogCustomerInput: entrada
            // , idempotencyKey: "VENTA-2026-000123" // opcional: si falta, el SDK pone una y la repite en los reintentos
        );
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}

```

#### Go

```go
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"os"

	trevol "github.com/trevol-si/trevol-go"
	"github.com/trevol-si/trevol-go/generado"
)

func main() {
	ctx := context.Background()
	c, err := trevol.NewClient(os.Getenv("TREVOL_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	var entrada generado.CatalogCustomerInput
	cuerpo := `{
  "external_id": "ERP-CLI-0042",
  "document_type": "31",
  "document_number": "900373427",
  "name": "DISTRIBUIDORA LOS ANDES SAS",
  "person_type": "legal",
  "tax_responsibilities": [
    "O-13"
  ],
  "email": "facturacion@distribuidoralosandes.example",
  "phone": "6045550142",
  "address": "Carrera 43A # 1-50, Oficina 302",
  "city": "Medellín",
  "municipality_code": "05001",
  "defaults": {
    "payment_form": "credit",
    "term_days": 30,
    "payment_method": "47",
    "withholding_agent": true
  }
}`
	if err := json.Unmarshal([]byte(cuerpo), &entrada); err != nil {
		log.Fatal(err)
	}

	resultado, _, err := c.CustomersAPI.CreateCustomer(ctx).
		CatalogCustomerInput(entrada).
		// IdempotencyKey("VENTA-2026-000123"). // opcional: si falta, el SDK pone una y la repite en los reintentos
		Execute()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resultado)
}

```

#### Ruby

```ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.customers.create_customer(
  {
    external_id: 'ERP-CLI-0042',
    document_type: '31',
    document_number: '900373427',
    name: 'DISTRIBUIDORA LOS ANDES SAS',
    person_type: 'legal',
    tax_responsibilities: ['O-13'],
    email: 'facturacion@distribuidoralosandes.example',
    phone: '6045550142',
    address: 'Carrera 43A # 1-50, Oficina 302',
    city: 'Medellín',
    municipality_code: '05001',
    defaults: {
      payment_form: 'credit',
      term_days: 30,
      payment_method: '47',
      withholding_agent: true
    }
  },
  # idempotency_key: 'VENTA-2026-000123' # opcional: si falta, el SDK pone una y la repite en los reintentos
)
pp resultado.to_hash

```

#### Respuesta 201

```json
{
  "id": "cus_7d2e9f40a1b84c3e9a6f5b2c1d0e3f4a",
  "object": "customer",
  "document_type": "31",
  "document_number": "900373427",
  "check_digit": 6,
  "name": "DISTRIBUIDORA LOS ANDES SAS",
  "trade_name": null,
  "person_type": "legal",
  "tax_responsibilities": [
    "O-13"
  ],
  "email": "facturacion@distribuidoralosandes.example",
  "phone": "6045550142",
  "address": "Carrera 43A # 1-50, Oficina 302",
  "city": "Medellín",
  "department": "Antioquia",
  "municipality_code": "05001",
  "department_code": "05",
  "country": "CO",
  "defaults": {
    "payment_form": "credit",
    "term_days": 30,
    "payment_method": "47",
    "withholding_agent": true
  },
  "active": true,
  "source": "user",
  "stats": {
    "documents": 0,
    "total_invoiced": "0",
    "first_purchase_on": null,
    "last_purchase_on": null
  },
  "external_id": "ERP-CLI-0042",
  "personal_data": "visible",
  "created_at": "2026-11-18T08:30:00-05:00",
  "updated_at": "2026-11-18T08:30:00-05:00"
}
```

[Probar en el Playground](https://platform.trevol.si/playground?op=createCustomer&ejemplo=nit)

## Listar y buscar clientes

`GET /v1/customers` · `listCustomers`

Los clientes de la empresa de la llave, de la A a la Z por nombre. Filtros: `q` (de 2 a 100 caracteres: cada palabra, sin tildes ni mayúsculas, en el nombre, el nombre comercial o el documento), `document_number` (exacto), `external_id` y `active` (`true` o `false`; sin él, todos). Paginación por cursor: `limit` (1 a 100, 20 por defecto) y `starting_after` (el `id` del último de la página). Sin `customers:read`, `q` busca solo en el nombre y el nombre comercial. Ojo: `q` y `document_number` viajan en la URL (y en los registros de quien la guarde). `stats` es de la última sincronización con la DIAN. El documento, el DV, el correo y el teléfono de los clientes son del permiso `customers:read` de la llave (se marca al crearla): sin él, cualquier llave los recibe en `null` con `personal_data: "redacted"`, y buscar por documento (`document_number`, o un `q` que es un número de documento) es 403 `permission_denied` con `required_permission: "customers:read"`. Lo mismo en TODO lo que devuelve la API a esa llave: el `customer` de las facturas, las notas y el documento equivalente (con su `qr`, que lleva el documento del cliente, y el correo de la entrega), la contraparte de lo emitido en `/v1/dian_documents` y la columna del documento en `/v1/reports/documents`; y un `duplicate_customer` por documento no dice cuál es (`existing_id`). Los archivos de un documento emitido con Trevol (`…/pdf`, `…/xml`, `…/zip`) son el documento fiscal y lo traen como se emitió. Cada empresa tiene dos catálogos, uno por ambiente, y la llave decide cuál usa: con una de producción (`tvl_live_`), el de producción (el mismo de la app, Clientes y Productos, y el que llena la sincronización con la DIAN); con una de prueba (`tvl_test_`), el de habilitación, aparte y vacío al comienzo. Un id del otro ambiente es 404, como uno que no existe. Crear exige una llave de escritura e `Idempotency-Key`; editar exige una llave de escritura. Las escrituras cuentan en el límite de lecturas (600 por minuto), no en el tope diario de documentos; las altas tienen su tope: 10.000 clientes y 10.000 productos nuevos al día por empresa y ambiente (429 `rate_limited` con `limit: "catalog_daily"`). No hay DELETE: se desactiva con `PATCH {"active": false}` y se reactiva con `{"active": true}`; uno desactivado no se puede facturar por id. Los cambios avisan por webhook (`customer.*`, `product.*`).

**Parámetros**

| Nombre | En | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- | --- |
| `q` | consulta | texto |  | Busca cada palabra (sin tildes ni mayúsculas). Viaja en la URL. |
| `document_number` | consulta | texto |  | El número exacto, sin DV. Viaja en la URL. |
| `external_id` | consulta | texto |  |  |
| `active` | consulta | booleano |  | Sin él: activos y desactivados. |
| `limit` | consulta | entero |  |  |
| `starting_after` | consulta | texto |  |  |

**Respuestas**

| Estado | Qué pasó |
| --- | --- |
| 200 | {object: list, data, has_more, next_cursor} (objeto) |
| 403 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| 404 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| 422 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| Error | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |

`GET /v1/customers` (`listCustomers`)

#### cURL

```bash
curl "https://api.trevol.si/v1/customers?limit=100" \
  -H "Authorization: Bearer $TREVOL_API_KEY"
```

#### Node.js

```javascript
import { Trevol } from '@trevol/sdk';

const trevol = new Trevol(); // lee TREVOL_API_KEY

for await (const item of trevol.paginate((cursor) => trevol.customers.listCustomers({ limit: 100, startingAfter: cursor }))) {
  console.log(item.id);
}
```

#### Python

```python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

for item in trevol.paginate(lambda cursor: trevol.customers.list_customers(limit=100, starting_after=cursor)):
    print(item.id)
```

#### PHP

```php
<?php

use Trevol\Trevol;

require __DIR__ . '/vendor/autoload.php';

$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'

foreach ($trevol->paginate(fn (?string $cursor) => $trevol->customers->listCustomers(limit: 100, starting_after: $cursor)) as $item) {
    echo $item->getId(), PHP_EOL;
}

```

#### Java

```java
import si.trevol.Trevol;
import si.trevol.generado.model.CustomerList;

public class Ejemplo {
    public static void main(String[] args) throws Exception {
        Trevol trevol = Trevol.builder().apiKey(System.getenv("TREVOL_API_KEY")).build(); // tvl_test_… → trevol.environment() == TEST

        for (var item : trevol.paginate(
                cursor -> trevol.customers().listCustomers().limit(100).startingAfter(cursor).execute(),
                CustomerList::getData)) {
            System.out.println(item.getId());
        }
    }
}

```

#### C#

```csharp
using System;
using System.Threading.Tasks;
using Trevol;

public static class Ejemplo
{
    public static async Task Main()
    {
        var trevol = new TrevolClient(Environment.GetEnvironmentVariable("TREVOL_API_KEY")); // tvl_test_… → trevol.Environment == TrevolEnvironment.Test

        await foreach (var item in trevol.PaginateAsync(cursor => trevol.Customers.ListCustomersAsync(limit: 100, startingAfter: cursor)))
        {
            Console.WriteLine(item.Id);
        }
    }
}

```

#### Go

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	trevol "github.com/trevol-si/trevol-go"
	"github.com/trevol-si/trevol-go/generado"
)

func main() {
	ctx := context.Background()
	c, err := trevol.NewClient(os.Getenv("TREVOL_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	for item, err := range trevol.Paginate(ctx, func(cursor *string) (*generado.CustomerList, error) {
		r := c.CustomersAPI.ListCustomers(ctx).Limit(100)
		if cursor != nil {
			r = r.StartingAfter(*cursor)
		}
		l, _, err := r.Execute()
		return l, err
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.GetId())
	}
}

```

#### Ruby

```ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

trevol.paginate { |cursor| trevol.customers.list_customers(limit: 100, starting_after: cursor) }.each do |item|
  puts item.id
end

```

#### Respuesta 200

```json
{
  "object": "list",
  "has_more": true,
  "next_cursor": "cus_7d2e9f40a1b84c3e9a6f5b2c1d0e3f4a",
  "data": [
    {
      "id": "cus_7d2e9f40a1b84c3e9a6f5b2c1d0e3f4a",
      "object": "customer",
      "document_type": "31",
      "document_number": "900373427",
      "check_digit": 6,
      "name": "DISTRIBUIDORA LOS ANDES SAS",
      "trade_name": null,
      "person_type": "legal",
      "tax_responsibilities": [
        "O-13"
      ],
      "email": "facturacion@distribuidoralosandes.example",
      "phone": "6045550142",
      "address": "Carrera 43A # 1-50, Oficina 302",
      "city": "Medellín",
      "department": "Antioquia",
      "municipality_code": "05001",
      "department_code": "05",
      "country": "CO",
      "defaults": {
        "payment_form": "credit",
        "term_days": 30,
        "payment_method": "47",
        "withholding_agent": true
      },
      "active": true,
      "source": "user",
      "stats": {
        "documents": 0,
        "total_invoiced": "0",
        "first_purchase_on": null,
        "last_purchase_on": null
      },
      "external_id": "ERP-CLI-0042",
      "personal_data": "visible",
      "created_at": "2026-11-18T08:30:00-05:00",
      "updated_at": "2026-11-18T08:30:00-05:00"
    }
  ]
}
```

[Probar en el Playground](https://platform.trevol.si/playground?op=listCustomers)

## Un cliente

`GET /v1/customers/{id}` · `retrieveCustomer`

Un cliente del catálogo de la empresa y del ambiente de la llave. Un id de otra empresa o del otro ambiente es 404, como uno que no existe. El documento, el DV, el correo y el teléfono de los clientes son del permiso `customers:read` de la llave (se marca al crearla): sin él, cualquier llave los recibe en `null` con `personal_data: "redacted"`, y buscar por documento (`document_number`, o un `q` que es un número de documento) es 403 `permission_denied` con `required_permission: "customers:read"`. Lo mismo en TODO lo que devuelve la API a esa llave: el `customer` de las facturas, las notas y el documento equivalente (con su `qr`, que lleva el documento del cliente, y el correo de la entrega), la contraparte de lo emitido en `/v1/dian_documents` y la columna del documento en `/v1/reports/documents`; y un `duplicate_customer` por documento no dice cuál es (`existing_id`). Los archivos de un documento emitido con Trevol (`…/pdf`, `…/xml`, `…/zip`) son el documento fiscal y lo traen como se emitió. 

**Parámetros**

| Nombre | En | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- | --- |
| `id` | ruta | texto | sí |  |

**Respuestas**

| Estado | Qué pasó |
| --- | --- |
| 200 | El cliente (sin customers:read, sin sus datos personales) ([CatalogCustomer](/docs/api/objetos#CatalogCustomer)) |
| 404 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| Error | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |

`GET /v1/customers/{id}` (`retrieveCustomer`)

#### cURL

```bash
curl "https://api.trevol.si/v1/customers/cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b" \
  -H "Authorization: Bearer $TREVOL_API_KEY"
```

#### Node.js

```javascript
import { Trevol } from '@trevol/sdk';

const trevol = new Trevol(); // lee TREVOL_API_KEY

const resultado = await trevol.customers.retrieveCustomer({
  id: 'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
});
console.log(resultado);
```

#### Python

```python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.customers.retrieve_customer(
    id="cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
)
print(resultado)
```

#### PHP

```php
<?php

use Trevol\Trevol;

require __DIR__ . '/vendor/autoload.php';

$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'

$resultado = $trevol->customers->retrieveCustomer(
    id: 'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
);
echo $resultado, PHP_EOL;

```

#### Java

```java
import si.trevol.Trevol;

public class Ejemplo {
    public static void main(String[] args) throws Exception {
        Trevol trevol = Trevol.builder().apiKey(System.getenv("TREVOL_API_KEY")).build(); // tvl_test_… → trevol.environment() == TEST

        var resultado = trevol.customers().retrieveCustomer("cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").execute();
        System.out.println(resultado);
    }
}

```

#### C#

```csharp
using System;
using System.Threading.Tasks;
using Trevol;

public static class Ejemplo
{
    public static async Task Main()
    {
        var trevol = new TrevolClient(Environment.GetEnvironmentVariable("TREVOL_API_KEY")); // tvl_test_… → trevol.Environment == TrevolEnvironment.Test

        var resultado = await trevol.Customers.RetrieveCustomerAsync(id: "cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b");
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}

```

#### Go

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	trevol "github.com/trevol-si/trevol-go"
)

func main() {
	ctx := context.Background()
	c, err := trevol.NewClient(os.Getenv("TREVOL_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	resultado, _, err := c.CustomersAPI.RetrieveCustomer(ctx, "cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").Execute()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resultado)
}

```

#### Ruby

```ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.customers.retrieve_customer(
  'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
)
pp resultado.to_hash

```

[Probar en el Playground](https://platform.trevol.si/playground?op=retrieveCustomer)

## Editar, desactivar o reactivar un cliente

`PATCH /v1/customers/{id}` · `updateCustomer`

Cambia solo los campos que mandas; `null` borra uno opcional (el nombre, el tipo y el número no se borran). Si cambia el número o el tipo, Trevol recalcula el DV. `{"active": false}` lo desactiva y `{"active": true}` lo reactiva. Lo que edita la API ya no lo pisa la sincronización (solo `stats`). Sin Idempotency-Key: repetir el mismo PATCH deja lo mismo. Un PATCH que no cambia nada devuelve el cliente como está, sin tocarlo.

**Parámetros**

| Nombre | En | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- | --- |
| `id` | ruta | texto | sí |  |

**Cuerpo** ([CatalogCustomerUpdate](/docs/api/objetos#CatalogCustomerUpdate), obligatorio)

| Campo | Tipo | Obligatorio | Descripción |
| --- | --- | --- | --- |
| `document_type` | `11` \| `12` \| `13` \| `21` \| `22` \| `31` \| `41` \| `42` \| `47` \| `48` \| `50` \| `91` |  | Tabla 13.2.1 de la DIAN: 13 CC, 31 NIT, 22 CE, 41 PA… |
| `document_number` | texto |  | Sin DV ni puntos. 11, 12, 13, 31 y 91 solo llevan números. |
| `check_digit` | entero (puede ser null) |  | Opcional: si viene, tiene que ser el DV del NIT. Si no, lo calcula Trevol. |
| `name` | texto |  |  |
| `trade_name` | texto (puede ser null) |  |  |
| `person_type` | `legal` \| `natural` \| `null` (puede ser null) |  |  |
| `tax_responsibilities` | lista de `R-99-PN` \| `O-13` \| `O-15` \| `O-23` \| `O-47` (puede ser null) |  | Tabla 13.2.6.1. R-99-PN (no responsable) no se combina con otras. Máximo 5. |
| `email` | texto (puede ser null) |  |  |
| `phone` | texto (puede ser null) |  |  |
| `address` | texto (puede ser null) |  |  |
| `city` | texto (puede ser null) |  |  |
| `municipality_code` | texto (puede ser null) |  | Código DANE del municipio (5 dígitos). El departamento sale de aquí. |
| `country` | texto (puede ser null) |  | ISO 3166-1 alfa-2. Por defecto CO. |
| `defaults` | decimal |  |  |
| `active` | booleano |  | false lo desactiva (no se puede facturar por id); true lo reactiva. |
| `external_id` | texto (puede ser null) |  | Tu id del registro (1 a 100 caracteres: letras, números y :._/-). Único por empresa; null lo borra. |

**Respuestas**

| Estado | Qué pasó |
| --- | --- |
| 200 | El cliente como queda ([CatalogCustomer](/docs/api/objetos#CatalogCustomer)) |
| 404 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| 409 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| 422 | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |
| Error | Error (application/problem+json) ([Problem](/docs/api/objetos#Problem)) |

`PATCH /v1/customers/{id}` (`updateCustomer`)

#### cURL

```bash
curl -X PATCH "https://api.trevol.si/v1/customers/cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b" \
  -H "Authorization: Bearer $TREVOL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "cartera@distribuidoralosandes.example",
  "defaults": {
    "term_days": 45
  }
}'
```

#### Node.js

```javascript
import { Trevol } from '@trevol/sdk';

const trevol = new Trevol(); // lee TREVOL_API_KEY

const resultado = await trevol.customers.updateCustomer({
  id: 'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
  catalogCustomerUpdate: {
    email: 'cartera@distribuidoralosandes.example',
    defaults: { term_days: 45 }
  }
});
console.log(resultado);
```

#### Python

```python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.customers.update_customer(
    id="cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
    catalog_customer_update={
        "email": "cartera@distribuidoralosandes.example",
        "defaults": {"term_days": 45},
    },
)
print(resultado)
```

#### PHP

```php
<?php

use Trevol\Trevol;

require __DIR__ . '/vendor/autoload.php';

$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'

$resultado = $trevol->customers->updateCustomer(
    id: 'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
    catalog_customer_update: [
        'email' => 'cartera@distribuidoralosandes.example',
        'defaults' => ['term_days' => 45],
    ],
);
echo $resultado, PHP_EOL;

```

#### Java

```java
import si.trevol.Trevol;
import si.trevol.generado.model.CatalogCustomerUpdate;

public class Ejemplo {
    public static void main(String[] args) throws Exception {
        Trevol trevol = Trevol.builder().apiKey(System.getenv("TREVOL_API_KEY")).build(); // tvl_test_… → trevol.environment() == TEST

        CatalogCustomerUpdate entrada = CatalogCustomerUpdate.fromJson("""
            {
              "email": "cartera@distribuidoralosandes.example",
              "defaults": {
                "term_days": 45
              }
            }
            """);
        var resultado = trevol.customers().updateCustomer("cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b", entrada).execute();
        System.out.println(resultado);
    }
}

```

#### C#

```csharp
using System;
using System.Threading.Tasks;
using Trevol;
using Trevol.Generado.Model;

public static class Ejemplo
{
    public static async Task Main()
    {
        var trevol = new TrevolClient(Environment.GetEnvironmentVariable("TREVOL_API_KEY")); // tvl_test_… → trevol.Environment == TrevolEnvironment.Test

        var entrada = TrevolJson.Deserialize<CatalogCustomerUpdate>("""
            {
              "email": "cartera@distribuidoralosandes.example",
              "defaults": {
                "term_days": 45
              }
            }
            """);
        var resultado = await trevol.Customers.UpdateCustomerAsync(
            id: "cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
            catalogCustomerUpdate: entrada
        );
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}

```

#### Go

```go
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"os"

	trevol "github.com/trevol-si/trevol-go"
	"github.com/trevol-si/trevol-go/generado"
)

func main() {
	ctx := context.Background()
	c, err := trevol.NewClient(os.Getenv("TREVOL_API_KEY"))
	if err != nil {
		log.Fatal(err)
	}

	var entrada generado.CatalogCustomerUpdate
	cuerpo := `{
  "email": "cartera@distribuidoralosandes.example",
  "defaults": {
    "term_days": 45
  }
}`
	if err := json.Unmarshal([]byte(cuerpo), &entrada); err != nil {
		log.Fatal(err)
	}

	resultado, _, err := c.CustomersAPI.UpdateCustomer(ctx, "cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").
		CatalogCustomerUpdate(entrada).
		Execute()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resultado)
}

```

#### Ruby

```ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.customers.update_customer(
  'cus_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
  {
    email: 'cartera@distribuidoralosandes.example',
    defaults: { term_days: 45 }
  }
)
pp resultado.to_hash

```

#### Respuesta 200

```json
{
  "id": "cus_7d2e9f40a1b84c3e9a6f5b2c1d0e3f4a",
  "object": "customer",
  "document_type": "31",
  "document_number": "900373427",
  "check_digit": 6,
  "name": "DISTRIBUIDORA LOS ANDES SAS",
  "trade_name": null,
  "person_type": "legal",
  "tax_responsibilities": [
    "O-13"
  ],
  "email": "facturacion@distribuidoralosandes.example",
  "phone": "6045550142",
  "address": "Carrera 43A # 1-50, Oficina 302",
  "city": "Medellín",
  "department": "Antioquia",
  "municipality_code": "05001",
  "department_code": "05",
  "country": "CO",
  "defaults": {
    "payment_form": "credit",
    "term_days": 30,
    "payment_method": "47",
    "withholding_agent": true
  },
  "active": true,
  "source": "user",
  "stats": {
    "documents": 0,
    "total_invoiced": "0",
    "first_purchase_on": null,
    "last_purchase_on": null
  },
  "external_id": "ERP-CLI-0042",
  "personal_data": "visible",
  "created_at": "2026-11-18T08:30:00-05:00",
  "updated_at": "2026-11-18T08:30:00-05:00"
}
```

[Probar en el Playground](https://platform.trevol.si/playground?op=updateCustomer&ejemplo=cambio)
