Numeraciones
Las operaciones de Numeraciones de la API de Trevol: parámetros, cuerpo, respuestas y ejemplos de código.
Los rangos de numeración de la empresa (los de Trevol y lo que muestra el portal de la DIAN), asociar a Trevol uno que ya tiene y pedir uno nuevo a la DIAN (formulario 1302), con su seguimiento.
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.
Volver a leer los rangos en el portal de la DIAN
POST /v1/numbering_ranges/refresh · refreshNumberingRanges
Que Trevol vuelva a leer los rangos de la empresa en el portal de la DIAN (en segundo plano: 202). Si ya hay una lectura en curso, responde esa. Mientras la lectura no tenga precio (operation_prices.numbering_refresh en 0), una por empresa cada 30 minutos; con precio, una cada 5 minutos (la de la app también cuenta; si no, 429 rate_limited con Retry-After); la empresa tiene que estar habilitada. Con una llave test es SIMULADA (simulated: true): no toca el portal, termina sola en unos segundos y se puede repetir cada 2 minutos. portal_read_at es la última lectura terminada: consulta GET /v1/numbering_ranges cuando cambie. Se cobra del saldo (solo en producción) el precio de operation_prices en GET /v1/balance (0 = gratis): se aparta al crearla, se cobra si termina bien y se devuelve si falla. Sin saldo: 402 insufficient_balance (con balance_cop y price_cop) y no se crea nada.
Respuestas
| Estado | Qué pasó |
|---|---|
| 202 | La lectura, encolada o en curso (NumberingRefresh) |
| 402 | Error (application/problem+json) (Problem) |
| 403 | Error (application/problem+json) (Problem) |
| 409 | Error (application/problem+json) (Problem) |
| 422 | Error (application/problem+json) (Problem) |
| 429 | Error (application/problem+json) (Problem) |
| Error | Error (application/problem+json) (Problem) |
POST /v1/numbering_ranges/refresh
curl -X POST "https://api.trevol.si/v1/numbering_ranges/refresh" \
-H "Authorization: Bearer $TREVOL_API_KEY"import { Trevol } from '@trevol/sdk';
const trevol = new Trevol(); // lee TREVOL_API_KEY
const resultado = await trevol.numberingRanges.refreshNumberingRanges();
console.log(resultado);from trevol import Trevol
trevol = Trevol() # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.refresh_numbering_ranges()
print(resultado)<?php
use Trevol\Trevol;
require __DIR__ . '/vendor/autoload.php';
$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'
$resultado = $trevol->numberingRanges->refreshNumberingRanges();
echo $resultado, PHP_EOL;
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.numberingRanges().refreshNumberingRanges().execute();
System.out.println(resultado);
}
}
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.NumberingRanges.RefreshNumberingRangesAsync();
Console.WriteLine(TrevolJson.Serialize(resultado));
}
}
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.NumberingRangesAPI.RefreshNumberingRanges(ctx).Execute()
if err != nil {
log.Fatal(err)
}
fmt.Println(resultado)
}
require 'trevol'
trevol = Trevol::Client.new # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.refresh_numbering_ranges
pp resultado.to_hash
{
"object": "numbering_refresh",
"status": "pending",
"portal_read_at": "2026-11-18T09:02:11-05:00"
}Asociar a Trevol un rango que la empresa ya tiene
POST /v1/numbering_ranges/{id}/associate · associateNumberingRange
Asocia a Trevol un rango que la empresa ya tiene en la DIAN (el id de GET /v1/numbering_ranges), para facturar con él. El trabajo lo hace Trevol en el portal (202 numbering_association; síguelo con GET /v1/numbering_associations/{id} o con los webhooks numbering_range.associated / numbering_range.association_failed) y después trae la resolución y su clave técnica. Si el rango está en otro software, se quita de ahí SOLO con {"remove_from_current_software": true}: sin él, 409 confirmation_required con el nombre y el proveedor de ese software (al pasarlo a Trevol, ese software ya no puede facturar con él). Exige Idempotency-Key. 404 si el rango no es de la empresa; 409 portal_read_required si no apareció en la última lectura del portal; 409 range_protected, company_busy (otro trámite en curso, reintentable). Hasta 10 por empresa al día mientras es gratis; con precio, hasta 60 (429). Con una llave test es SIMULADA (hasta 50 al día): solo los rangos simulados (simulated: true), sin tocar el portal; un rango pedido con el prefijo OTRO está en otro software (para probar confirmation_required) y uno pedido con NOAS falla al asociar. Se cobra del saldo (solo en producción) el precio de operation_prices en GET /v1/balance (0 = gratis): se aparta al crearla, se cobra si termina bien y se devuelve si falla. Sin saldo: 402 insufficient_balance (con balance_cop y price_cop) y no se crea nada; la misma Idempotency-Key sirve después de recargar.
Parámetros
Idempotency-KeycabeceratextoobligatorioObligatoria: 1 a 255 caracteres ASCII visibles, única por pedido (7 días).
Cuerpo (NumberingAssociationInput)
remove_from_current_softwarebooleanoSolo el booleanotruequita el rango del software donde está (ese software ya no podrá facturar con él);falseo sin el campo, no se quita.
Respuestas
| Estado | Qué pasó |
|---|---|
| 202 | La asociación, encolada (NumberingAssociation) |
| 402 | Error (application/problem+json) (Problem) |
| 403 | Error (application/problem+json) (Problem) |
| 404 | Error (application/problem+json) (Problem) |
| 409 | Error (application/problem+json) (Problem) |
| 422 | Error (application/problem+json) (Problem) |
| 429 | Error (application/problem+json) (Problem) |
| Error | Error (application/problem+json) (Problem) |
POST /v1/numbering_ranges/{id}/associate
curl -X POST "https://api.trevol.si/v1/numbering_ranges/nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b/associate" \
-H "Authorization: Bearer $TREVOL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"remove_from_current_software": true
}'import { Trevol } from '@trevol/sdk';
const trevol = new Trevol(); // lee TREVOL_API_KEY
const resultado = await trevol.numberingRanges.associateNumberingRange({
id: 'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
numberingAssociationInput: { remove_from_current_software: true },
// idempotencyKey: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
});
console.log(resultado);from trevol import Trevol
trevol = Trevol() # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.associate_numbering_range(
id="nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
numbering_association_input={"remove_from_current_software": True},
# idempotency_key="VENTA-2026-000123", # opcional: si falta, el SDK pone una y la repite en los reintentos
)
print(resultado)<?php
use Trevol\Trevol;
require __DIR__ . '/vendor/autoload.php';
$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'
$resultado = $trevol->numberingRanges->associateNumberingRange(
id: 'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
numbering_association_input: ['remove_from_current_software' => true],
// idempotency_key: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
);
echo $resultado, PHP_EOL;
import si.trevol.Trevol;
import si.trevol.generado.model.NumberingAssociationInput;
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
NumberingAssociationInput entrada = NumberingAssociationInput.fromJson("""
{
"remove_from_current_software": true
}
""");
var resultado = trevol.numberingRanges().associateNumberingRange("nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b")
.numberingAssociationInput(entrada)
// .idempotencyKey("VENTA-2026-000123") // opcional: si falta, el SDK pone una y la repite en los reintentos
.execute();
System.out.println(resultado);
}
}
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<NumberingAssociationInput>("""
{
"remove_from_current_software": true
}
""");
var resultado = await trevol.NumberingRanges.AssociateNumberingRangeAsync(
id: "nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
numberingAssociationInput: entrada
// , idempotencyKey: "VENTA-2026-000123" // opcional: si falta, el SDK pone una y la repite en los reintentos
);
Console.WriteLine(TrevolJson.Serialize(resultado));
}
}
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.NumberingAssociationInput
cuerpo := `{
"remove_from_current_software": true
}`
if err := json.Unmarshal([]byte(cuerpo), &entrada); err != nil {
log.Fatal(err)
}
resultado, _, err := c.NumberingRangesAPI.AssociateNumberingRange(ctx, "nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").
NumberingAssociationInput(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)
}
require 'trevol'
trevol = Trevol::Client.new # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.associate_numbering_range(
'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
{ remove_from_current_software: true },
# idempotency_key: 'VENTA-2026-000123' # opcional: si falta, el SDK pone una y la repite en los reintentos
)
pp resultado.to_hash
{
"id": "nas_9e8d7c6b9e8d7c6b9e8d7c6b9e8d7c6b",
"object": "numbering_association",
"numbering_range_id": "nrg_7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d",
"removed_from_other_software": true,
"status": "pending",
"error": null,
"created_at": "2026-11-18T09:25:40-05:00",
"finished_at": null
}Los rangos de numeración de la empresa
GET /v1/numbering_ranges · listNumberingRanges
Los rangos de numeración de la empresa de la llave en su ambiente, por prefijo y número de resolución. Con una llave live: las resoluciones de producción en Trevol y lo que el portal de la DIAN muestra de la empresa (también rangos que no están en Trevol), con software.association (trevol, other —con el nombre y el proveedor del otro software—, none si está libre o unknown sin dato del portal), next_number (después de lo que Trevol reservó y de lo que la DIAN ya conoce), remaining, el último uso de otro programa, si es la predeterminada, si sirve (usable / unusable_reason) y si hay clave técnica (nunca su valor). Con una llave test: las resoluciones de habilitación (sin datos del portal) y los rangos SIMULADOS que salen de tus solicitudes simuladas (simulated: true; nunca sirven para emitir: unusable_reason: simulated). Los vencidos no salen salvo include_expired=true. Filtros document y association; paginación por cursor (limit, starting_after). Para traer lo último del portal, POST /v1/numbering_ranges/refresh.
Parámetros
limitconsultaenterostarting_afterconsultatextodocumentconsultainvoice|support_document|equivalent_documentassociationconsultatrevol|other|none|unknowninclude_expiredconsultabooleanotrue para ver también los vencidos.
Respuestas
GET /v1/numbering_ranges
curl "https://api.trevol.si/v1/numbering_ranges?limit=100" \
-H "Authorization: Bearer $TREVOL_API_KEY"import { Trevol } from '@trevol/sdk';
const trevol = new Trevol(); // lee TREVOL_API_KEY
for await (const item of trevol.paginate((cursor) => trevol.numberingRanges.listNumberingRanges({ limit: 100, startingAfter: cursor }))) {
console.log(item.id);
}from trevol import Trevol
trevol = Trevol() # lee TREVOL_API_KEY
for item in trevol.paginate(lambda cursor: trevol.numbering_ranges.list_numbering_ranges(limit=100, starting_after=cursor)):
print(item.id)<?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->numberingRanges->listNumberingRanges(limit: 100, starting_after: $cursor)) as $item) {
echo $item->getId(), PHP_EOL;
}
import si.trevol.Trevol;
import si.trevol.generado.model.NumberingRangeList;
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.numberingRanges().listNumberingRanges().limit(100).startingAfter(cursor).execute(),
NumberingRangeList::getData)) {
System.out.println(item.getId());
}
}
}
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.NumberingRanges.ListNumberingRangesAsync(limit: 100, startingAfter: cursor)))
{
Console.WriteLine(item.Id);
}
}
}
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.NumberingRangeList, error) {
r := c.NumberingRangesAPI.ListNumberingRanges(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())
}
}
require 'trevol'
trevol = Trevol::Client.new # lee TREVOL_API_KEY
trevol.paginate { |cursor| trevol.numbering_ranges.list_numbering_ranges(limit: 100, starting_after: cursor) }.each do |item|
puts item.id
end
{
"object": "list",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "nrg_7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d",
"object": "numbering_range",
"environment": "live",
"document": "invoice",
"prefix": "FG",
"resolution_number": "18764000098765",
"from": 1,
"to": 1000,
"valid_from": "2025-06-10",
"valid_to": "2027-06-10",
"days_until_expiry": 204,
"next_number": 734,
"remaining": 267,
"last_external_use_on": "2026-11-15",
"software": {
"association": "other",
"name": "Facturación gratuita DIAN",
"provider": "DIAN"
},
"in_trevol": false,
"active": false,
"default": false,
"usable": false,
"unusable_reason": "not_in_trevol",
"has_technical_key": false,
"associated_on": "2025-06-11",
"portal_read_at": "2026-11-18T09:02:11-05:00"
},
{
"id": "nrg_5d1e8a7c3b2f4e6a9c0d1b2a3f4e5d6c",
"object": "numbering_range",
"environment": "live",
"document": "invoice",
"prefix": "LA",
"resolution_number": "18764000123456",
"from": 1,
"to": 5000,
"valid_from": "2026-03-01",
"valid_to": "2028-03-01",
"days_until_expiry": 469,
"next_number": 1290,
"remaining": 3711,
"last_external_use_on": null,
"software": {
"association": "trevol",
"name": "Trevol",
"provider": "TREVOL"
},
"in_trevol": true,
"active": true,
"default": true,
"usable": true,
"unusable_reason": null,
"has_technical_key": true,
"associated_on": "2026-03-02",
"portal_read_at": "2026-11-18T09:02:11-05:00"
}
]
}Un rango de numeración
GET /v1/numbering_ranges/{id} · retrieveNumberingRange
Un rango de la empresa de la llave en su ambiente (también uno vencido). 404 si no es de esta empresa y este ambiente.
Respuestas
| Estado | Qué pasó |
|---|---|
| 200 | El rango (NumberingRange) |
| 404 | Error (application/problem+json) (Problem) |
| Error | Error (application/problem+json) (Problem) |
GET /v1/numbering_ranges/{id}
curl "https://api.trevol.si/v1/numbering_ranges/nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b" \
-H "Authorization: Bearer $TREVOL_API_KEY"import { Trevol } from '@trevol/sdk';
const trevol = new Trevol(); // lee TREVOL_API_KEY
const resultado = await trevol.numberingRanges.retrieveNumberingRange({
id: 'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
});
console.log(resultado);from trevol import Trevol
trevol = Trevol() # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.retrieve_numbering_range(
id="nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
)
print(resultado)<?php
use Trevol\Trevol;
require __DIR__ . '/vendor/autoload.php';
$trevol = new Trevol(getenv('TREVOL_API_KEY')); // tvl_test_… → $trevol->environment === 'test'
$resultado = $trevol->numberingRanges->retrieveNumberingRange(
id: 'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
);
echo $resultado, PHP_EOL;
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.numberingRanges().retrieveNumberingRange("nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").execute();
System.out.println(resultado);
}
}
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.NumberingRanges.RetrieveNumberingRangeAsync(id: "nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b");
Console.WriteLine(TrevolJson.Serialize(resultado));
}
}
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.NumberingRangesAPI.RetrieveNumberingRange(ctx, "nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").Execute()
if err != nil {
log.Fatal(err)
}
fmt.Println(resultado)
}
require 'trevol'
trevol = Trevol::Client.new # lee TREVOL_API_KEY
resultado = trevol.numbering_ranges.retrieve_numbering_range(
'nrg_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
)
pp resultado.to_hash
{
"id": "nrg_5d1e8a7c3b2f4e6a9c0d1b2a3f4e5d6c",
"object": "numbering_range",
"environment": "live",
"document": "invoice",
"prefix": "LA",
"resolution_number": "18764000123456",
"from": 1,
"to": 5000,
"valid_from": "2026-03-01",
"valid_to": "2028-03-01",
"days_until_expiry": 469,
"next_number": 1290,
"remaining": 3711,
"last_external_use_on": null,
"software": {
"association": "trevol",
"name": "Trevol",
"provider": "TREVOL"
},
"in_trevol": true,
"active": true,
"default": true,
"usable": true,
"unusable_reason": null,
"has_technical_key": true,
"associated_on": "2026-03-02",
"portal_read_at": "2026-11-18T09:02:11-05:00"
}