Ejemplos / Regímenes y casos especiales
Factura Verifactu: bienes usados (REBU)
Ejemplo de la API Verifactu: el JSON que envías a la AEAT con POST /tbai/, el mismo código en PHP y otros lenguajes, y la respuesta que recibes.
Actualizado el
En el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (REBU) el IVA solo grava el margen: precio de venta menos precio de compra. Envía regimen_iva: "03", una línea con la base del margen al 21 % y, en total_factura, el precio de venta completo.
En el ejemplo, un reloj comprado por 400 € se vende por 521 €: el margen es 121 € con IVA, es decir, 100 € de base y 21 € de IVA. A la AEAT llega un único desglose con ClaveRegimen 03, base 100 y cuota 21, e ImporteTotal 521.
No envíes el precio de compra como una línea a IVA 0: se declararía como operación exenta.
{
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "12345678Z",
"nombre": "Ane Etxeberria Garai",
"direccion": "Calle Mayor 1",
"cp": "01001",
"pais_cliente": "ES",
"serie": "RB2026",
"numero": "0014",
"simplificada": false,
"rectificativa": false,
"regimen_iva": "03",
"tipo_operacion": "bienes",
"retencion": 0,
"lineas": [
{
"descripcion": "Reloj de pulsera de segunda mano (margen)",
"cantidad": 1,
"importe_unitario": 100,
"tipo_iva": 21,
"tipo_req": 0
}
],
"total_factura": 521
}
<?php
// composer require ticketbaiws/ticketbaiws-php
require 'vendor/autoload.php';
$tbai = new \TicketbaiWS\Client('TU_TOKEN_DE_TEST', 'B89670855', ['entorno' => 'test']);
$r = $tbai->crearFactura([
'fecha' => '03/12/2026',
'hora' => '10:30:00',
'nif' => '12345678Z',
'nombre' => 'Ane Etxeberria Garai',
'direccion' => 'Calle Mayor 1',
'cp' => '01001',
'pais_cliente' => 'ES',
'serie' => 'RB2026',
'numero' => '0014',
'simplificada' => false,
'rectificativa' => false,
'regimen_iva' => '03',
'tipo_operacion' => 'bienes',
'retencion' => 0,
'lineas' => [
['descripcion' => 'Reloj de pulsera de segunda mano (margen)', 'cantidad' => 1, 'importe_unitario' => 100, 'tipo_iva' => 21, 'tipo_req' => 0],
],
'total_factura' => 521,
]);
if ($r->isError()) {
throw new RuntimeException($r->getMessageText());
}
// $r->getData('qr') es el PNG del QR en base64 para imprimir en la factura
curl -X POST 'https://api-test.verifactu.ws/tbai/' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Token: TU_TOKEN_DE_TEST' \
-H 'Nif: B89670855' \
--data-binary @- <<'JSON'
{
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "12345678Z",
"nombre": "Ane Etxeberria Garai",
"direccion": "Calle Mayor 1",
"cp": "01001",
"pais_cliente": "ES",
"serie": "RB2026",
"numero": "0014",
"simplificada": false,
"rectificativa": false,
"regimen_iva": "03",
"tipo_operacion": "bienes",
"retencion": 0,
"lineas": [
{
"descripcion": "Reloj de pulsera de segunda mano (margen)",
"cantidad": 1,
"importe_unitario": 100,
"tipo_iva": 21,
"tipo_req": 0
}
],
"total_factura": 521
}
JSON
const datos = {
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "12345678Z",
"nombre": "Ane Etxeberria Garai",
"direccion": "Calle Mayor 1",
"cp": "01001",
"pais_cliente": "ES",
"serie": "RB2026",
"numero": "0014",
"simplificada": false,
"rectificativa": false,
"regimen_iva": "03",
"tipo_operacion": "bienes",
"retencion": 0,
"lineas": [
{
"descripcion": "Reloj de pulsera de segunda mano (margen)",
"cantidad": 1,
"importe_unitario": 100,
"tipo_iva": 21,
"tipo_req": 0
}
],
"total_factura": 521
};
const r = await fetch("https://api-test.verifactu.ws/tbai/", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Token": "TU_TOKEN_DE_TEST",
"Nif": "B89670855",
},
body: JSON.stringify(datos),
});
const respuesta = await r.json();
if (respuesta.result === "ERROR") throw new Error(respuesta.msg);
console.log(respuesta.return);
import json
import requests
datos = json.loads(r"""
{
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "12345678Z",
"nombre": "Ane Etxeberria Garai",
"direccion": "Calle Mayor 1",
"cp": "01001",
"pais_cliente": "ES",
"serie": "RB2026",
"numero": "0014",
"simplificada": false,
"rectificativa": false,
"regimen_iva": "03",
"tipo_operacion": "bienes",
"retencion": 0,
"lineas": [
{
"descripcion": "Reloj de pulsera de segunda mano (margen)",
"cantidad": 1,
"importe_unitario": 100,
"tipo_iva": 21,
"tipo_req": 0
}
],
"total_factura": 521
}
""")
r = requests.request(
"POST",
"https://api-test.verifactu.ws/tbai/",
headers={"Token": "TU_TOKEN_DE_TEST", "Nif": "B89670855", "Accept": "application/json"},
json=datos,
timeout=30,
)
respuesta = r.json()
if respuesta["result"] == "ERROR":
raise Exception(respuesta["msg"])
print(respuesta["return"])
using System.Net.Http;
using System.Text;
var json = """
{
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "12345678Z",
"nombre": "Ane Etxeberria Garai",
"direccion": "Calle Mayor 1",
"cp": "01001",
"pais_cliente": "ES",
"serie": "RB2026",
"numero": "0014",
"simplificada": false,
"rectificativa": false,
"regimen_iva": "03",
"tipo_operacion": "bienes",
"retencion": 0,
"lineas": [
{
"descripcion": "Reloj de pulsera de segunda mano (margen)",
"cantidad": 1,
"importe_unitario": 100,
"tipo_iva": 21,
"tipo_req": 0
}
],
"total_factura": 521
}
""";
using var http = new HttpClient();
var peticion = new HttpRequestMessage(new HttpMethod("POST"), "https://api-test.verifactu.ws/tbai/")
{
Content = new StringContent(json, Encoding.UTF8, "application/json")
};
peticion.Headers.Add("Token", "TU_TOKEN_DE_TEST");
peticion.Headers.Add("Nif", "B89670855");
var respuesta = await http.SendAsync(peticion);
Console.WriteLine(await respuesta.Content.ReadAsStringAsync());
Respuesta de ejemplo
{
"result": "PENDING",
"return": {
"huella": "A77B1437254799A3AEAC2D2C8A4552BAF5FF0D7DADB80C03AC142434A78EBD85",
"qr": "iVBORw0KGgo… (PNG en base64)",
"url": "https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR?nif=B89670855&numserie=RB20260014&fecha=03-12-2026&importe=521.00"
},
"msg": null
}- Los importes de las líneas van sin IVA. La API responde siempre con HTTP 200: comprueba
result(OK,PENDINGoERROR). - Sin
"sincrono": truela respuesta esPENDINGy la factura se envía a la AEAT en segundo plano. El resultado llega por webhook o conGET /tbai/. - Imprime en la factura el QR (
return.qr, PNG en base64) y la leyenda «VERI*FACTU».