Saltar al contenido
Menú
Saltar la navegación de la documentación

Versión 2026-11-18

Reportes asíncronos

Las operaciones de Reportes asíncronos de la API de Trevol: parámetros, cuerpo, respuestas y ejemplos de código.

Ver como Markdown

El IVA y el INC de un periodo para la declaración, y lo emitido y lo recibido en CSV o Excel. Solo lectura: cuenta lo válido ante la DIAN y dice lo que no pudo contar.

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.

Pedir un reporte asíncrono (periodos grandes)

POST /v1/report_runs · createReportRun

El archivo de GET /v1/reports/documents, generado en segundo plano: hasta 366 días y 250.000 documentos. 202 con el report_run; cuando esté listo llega report.ready (o report.failed) y el archivo se pide con GET /v1/report_runs/{id}/file (dura 24 horas). Exige Idempotency-Key. Cualquier llave; no se cobra. Por empresa y ambiente: 2 en curso y 20 en 24 horas (429 con limit: report_runs).

Parámetros

  • Idempotency-Keycabeceratextoobligatorio
    Obligatoria: 1 a 255 caracteres ASCII visibles, única por pedido (7 días).

Cuerpo (ReportRunInput, obligatorio)

  • reportdocumentsobligatorio
    El reporte: lo emitido y lo recibido, una fila por documento (el de GET /v1/reports/documents).
  • formatcsv | xlsxobligatorio
  • issued_fromfecha (AAAA-MM-DD)obligatorio
    Desde esta fecha de expedición (incluida, Bogotá).
  • issued_tofecha (AAAA-MM-DD)obligatorio
    Hasta esta fecha (incluida). A lo sumo 366 días.
  • directionissued | received | all
  • typecredit_note | debit_note | equivalent_document | equivalent_document_adjustment | invoice | other | support_document | support_document_adjustment

Respuestas

Estado Qué pasó
202 El reporte, en cola (ReportRun)
400 Error (application/problem+json) (Problem)
401 Error (application/problem+json) (Problem)
403 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/report_runs

cURL
curl -X POST "https://api.trevol.si/v1/report_runs" \
  -H "Authorization: Bearer $TREVOL_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "report": "documents",
  "format": "xlsx",
  "issued_from": "2026-01-01",
  "issued_to": "2026-10-31",
  "direction": "all"
}'
Node.js
import { Trevol } from '@trevol/sdk';

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

const resultado = await trevol.reportRuns.createReportRun({
  reportRunInput: {
    report: 'documents',
    format: 'xlsx',
    issued_from: '2026-01-01',
    issued_to: '2026-10-31',
    direction: 'all'
  },
  // idempotencyKey: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
});
console.log(resultado);
Python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.report_runs.create_report_run(
    report_run_input={
        "report": "documents",
        "format": "xlsx",
        "issued_from": "2026-01-01",
        "issued_to": "2026-10-31",
        "direction": "all",
    },
    # idempotency_key="VENTA-2026-000123",  # opcional: si falta, el SDK pone una y la repite en los reintentos
)
print(resultado)
PHP
<?php

use Trevol\Trevol;

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

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

$resultado = $trevol->reportRuns->createReportRun(
    report_run_input: [
        'report' => 'documents',
        'format' => 'xlsx',
        'issued_from' => '2026-01-01',
        'issued_to' => '2026-10-31',
        'direction' => 'all',
    ],
    // idempotency_key: 'VENTA-2026-000123', // opcional: si falta, el SDK pone una y la repite en los reintentos
);
echo $resultado, PHP_EOL;
Java
import si.trevol.Trevol;
import si.trevol.generado.model.ReportRunInput;

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

        ReportRunInput entrada = ReportRunInput.fromJson("""
            {
              "report": "documents",
              "format": "xlsx",
              "issued_from": "2026-01-01",
              "issued_to": "2026-10-31",
              "direction": "all"
            }
            """);
        var resultado = trevol.reportRuns().createReportRun(entrada)
                // .idempotencyKey("VENTA-2026-000123") // opcional: si falta, el SDK pone una y la repite en los reintentos
                .execute();
        System.out.println(resultado);
    }
}
C#
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<ReportRunInput>("""
            {
              "report": "documents",
              "format": "xlsx",
              "issued_from": "2026-01-01",
              "issued_to": "2026-10-31",
              "direction": "all"
            }
            """);
        var resultado = await trevol.ReportRuns.CreateReportRunAsync(
            reportRunInput: entrada
            // , idempotencyKey: "VENTA-2026-000123" // opcional: si falta, el SDK pone una y la repite en los reintentos
        );
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}
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.ReportRunInput
	cuerpo := `{
  "report": "documents",
  "format": "xlsx",
  "issued_from": "2026-01-01",
  "issued_to": "2026-10-31",
  "direction": "all"
}`
	if err := json.Unmarshal([]byte(cuerpo), &entrada); err != nil {
		log.Fatal(err)
	}

	resultado, _, err := c.ReportRunsAPI.CreateReportRun(ctx).
		ReportRunInput(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
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.report_runs.create_report_run(
  {
    report: 'documents',
    format: 'xlsx',
    issued_from: '2026-01-01',
    issued_to: '2026-10-31',
    direction: 'all'
  },
  # idempotency_key: 'VENTA-2026-000123' # opcional: si falta, el SDK pone una y la repite en los reintentos
)
pp resultado.to_hash
Respuesta202 Accepted
{
  "id": "rrun_3c9a0f5e3c9a0f5e3c9a0f5e3c9a0f5e",
  "object": "report_run",
  "environment": "live",
  "status": "queued",
  "report": "documents",
  "format": "xlsx",
  "params": {
    "issued_from": "2026-01-01",
    "issued_to": "2026-10-31",
    "direction": "all",
    "type": null
  },
  "rows": 0,
  "size_bytes": null,
  "error": null,
  "created_at": "2026-11-18T09:30:00-05:00",
  "completed_at": null,
  "expires_at": null
}

Los reportes asíncronos de los últimos 30 días

GET /v1/report_runs · listReportRuns

Parámetros

  • limitconsultaentero
  • starting_afterconsultatexto
  • statusconsultaqueued | running | ready | failed | expired

Respuestas

Estado Qué pasó
200 {object: list, data, has_more, next_cursor} (objeto)
Error Error (application/problem+json) (Problem)

GET /v1/report_runs

cURL
curl "https://api.trevol.si/v1/report_runs?limit=100" \
  -H "Authorization: Bearer $TREVOL_API_KEY"
Node.js
import { Trevol } from '@trevol/sdk';

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

for await (const item of trevol.paginate((cursor) => trevol.reportRuns.listReportRuns({ limit: 100, startingAfter: cursor }))) {
  console.log(item.id);
}
Python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

for item in trevol.paginate(lambda cursor: trevol.report_runs.list_report_runs(limit=100, starting_after=cursor)):
    print(item.id)
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->reportRuns->listReportRuns(limit: 100, starting_after: $cursor)) as $item) {
    echo $item->getId(), PHP_EOL;
}
Java
import si.trevol.Trevol;
import si.trevol.generado.model.ReportRunList;

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.reportRuns().listReportRuns().limit(100).startingAfter(cursor).execute(),
                ReportRunList::getData)) {
            System.out.println(item.getId());
        }
    }
}
C#
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.ReportRuns.ListReportRunsAsync(limit: 100, startingAfter: cursor)))
        {
            Console.WriteLine(item.Id);
        }
    }
}
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.ReportRunList, error) {
		r := c.ReportRunsAPI.ListReportRuns(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
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

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

Probar en el Playground

Respuesta200 OK
{
  "object": "list",
  "has_more": false,
  "next_cursor": null,
  "data": [
    {
      "id": "rrun_3c9a0f5e3c9a0f5e3c9a0f5e3c9a0f5e",
      "object": "report_run",
      "environment": "live",
      "status": "ready",
      "report": "documents",
      "format": "xlsx",
      "params": {
        "issued_from": "2026-01-01",
        "issued_to": "2026-10-31",
        "direction": "all",
        "type": null
      },
      "rows": 48213,
      "size_bytes": 6829104,
      "error": null,
      "created_at": "2026-11-18T09:30:00-05:00",
      "completed_at": "2026-11-18T09:34:12-05:00",
      "expires_at": "2026-11-19T09:34:12-05:00"
    }
  ]
}

Un reporte asíncrono

GET /v1/report_runs/{id} · retrieveReportRun

Parámetros

  • idrutatextoobligatorio

Respuestas

Estado Qué pasó
200 El reporte (ReportRun)
404 Error (application/problem+json) (Problem)
Error Error (application/problem+json) (Problem)

GET /v1/report_runs/{id}

cURL
curl "https://api.trevol.si/v1/report_runs/rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b" \
  -H "Authorization: Bearer $TREVOL_API_KEY"
Node.js
import { Trevol } from '@trevol/sdk';

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

const resultado = await trevol.reportRuns.retrieveReportRun({
  id: 'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
});
console.log(resultado);
Python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.report_runs.retrieve_report_run(
    id="rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
)
print(resultado)
PHP
<?php

use Trevol\Trevol;

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

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

$resultado = $trevol->reportRuns->retrieveReportRun(
    id: 'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
);
echo $resultado, PHP_EOL;
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.reportRuns().retrieveReportRun("rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").execute();
        System.out.println(resultado);
    }
}
C#
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.ReportRuns.RetrieveReportRunAsync(id: "rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b");
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}
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.ReportRunsAPI.RetrieveReportRun(ctx, "rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").Execute()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resultado)
}
Ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.report_runs.retrieve_report_run(
  'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
)
pp resultado.to_hash

Probar en el Playground

Respuesta200 OK
{
  "id": "rrun_3c9a0f5e3c9a0f5e3c9a0f5e3c9a0f5e",
  "object": "report_run",
  "environment": "live",
  "status": "ready",
  "report": "documents",
  "format": "xlsx",
  "params": {
    "issued_from": "2026-01-01",
    "issued_to": "2026-10-31",
    "direction": "all",
    "type": null
  },
  "rows": 48213,
  "size_bytes": 6829104,
  "error": null,
  "created_at": "2026-11-18T09:30:00-05:00",
  "completed_at": "2026-11-18T09:34:12-05:00",
  "expires_at": "2026-11-19T09:34:12-05:00"
}

El enlace de descarga del archivo de un reporte

GET /v1/report_runs/{id}/file · retrieveReportRunFile

El archivo de un reporte listo: un enlace firmado que vale 5 minutos y descarga el CSV o el Excel con el nombre trevol-documentos-<desde>_<hasta>.<csv|xlsx> (sin el NIT ni el nombre de la empresa). Es JSON, no una redirección: descarga url SIN tu llave (el enlace ya lleva su permiso). Pide uno nuevo cuando venza. Si el reporte todavía se genera, falló o su archivo venció: 409 file_unavailable con reason (not_ready, failed o expired). Si lo pidió una llave con customers:read, el archivo trae el número de documento de los clientes y bajarlo pide ese permiso a la llave que lo baja: sin él, 403 permission_denied con required_permission: "customers:read".

Parámetros

  • idrutatextoobligatorio

Respuestas

Estado Qué pasó
200 El enlace firmado (JSON) (ReportFile)
403 Error (application/problem+json) (Problem)
404 Error (application/problem+json) (Problem)
409 Error (application/problem+json) (Problem)
Error Error (application/problem+json) (Problem)

GET /v1/report_runs/{id}/file

cURL
curl "https://api.trevol.si/v1/report_runs/rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b/file" \
  -H "Authorization: Bearer $TREVOL_API_KEY"
Node.js
import { Trevol } from '@trevol/sdk';

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

const resultado = await trevol.reportRuns.retrieveReportRunFile({
  id: 'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
});
console.log(resultado);
Python
from trevol import Trevol

trevol = Trevol()  # lee TREVOL_API_KEY

resultado = trevol.report_runs.retrieve_report_run_file(
    id="rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b",
)
print(resultado)
PHP
<?php

use Trevol\Trevol;

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

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

$resultado = $trevol->reportRuns->retrieveReportRunFile(
    id: 'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b',
);
echo $resultado, PHP_EOL;
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.reportRuns().retrieveReportRunFile("rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").execute();
        System.out.println(resultado);
    }
}
C#
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.ReportRuns.RetrieveReportRunFileAsync(id: "rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b");
        Console.WriteLine(TrevolJson.Serialize(resultado));
    }
}
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.ReportRunsAPI.RetrieveReportRunFile(ctx, "rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b").Execute()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resultado)
}
Ruby
require 'trevol'

trevol = Trevol::Client.new # lee TREVOL_API_KEY

resultado = trevol.report_runs.retrieve_report_run_file(
  'rrun_3f0c1a2b3f0c1a2b3f0c1a2b3f0c1a2b'
)
pp resultado.to_hash

Probar en el Playground

Respuesta200 OK
{
  "object": "report_file",
  "url": "https://descargas.ejemplo.com/reportes/…?token=…&download=trevol-documentos-2026-01-01_2026-10-31.xlsx",
  "expires_at": "2026-11-18T09:40:00-05:00",
  "filename": "trevol-documentos-2026-01-01_2026-10-31.xlsx",
  "size_bytes": 6829104
}