Ejemplos / Clientes en el extranjero
Factura Verifactu: servicios a empresa de fuera de la UE
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
POST /tbai/Verifactu
Servicios B2B a una empresa establecida fuera de la UE (por ejemplo, Reino Unido): no sujetos al IVA español. Se envían con exportacion: true y tipo_operacion: "servicios".
{
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "GB123456789",
"tipo_documento": "06",
"nombre": "Example Clinical Ltd",
"direccion": "100 Long Avenue, Reading",
"cp": "RG2 6GP",
"pais_cliente": "GB",
"serie": "A2026",
"numero": "000158",
"simplificada": false,
"rectificativa": false,
"exportacion": true,
"tipo_operacion": "servicios",
"retencion": 0,
"lineas": [
{
"descripcion": "Estudio clínico — fase 2, centro 246",
"cantidad": 1,
"importe_unitario": 8764.78,
"tipo_iva": 0,
"tipo_req": 0
}
],
"total_factura": 8764.78
}
<?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' => 'GB123456789',
'tipo_documento' => '06',
'nombre' => 'Example Clinical Ltd',
'direccion' => '100 Long Avenue, Reading',
'cp' => 'RG2 6GP',
'pais_cliente' => 'GB',
'serie' => 'A2026',
'numero' => '000158',
'simplificada' => false,
'rectificativa' => false,
'exportacion' => true,
'tipo_operacion' => 'servicios',
'retencion' => 0,
'lineas' => [
['descripcion' => 'Estudio clínico — fase 2, centro 246', 'cantidad' => 1, 'importe_unitario' => 8764.78, 'tipo_iva' => 0, 'tipo_req' => 0],
],
'total_factura' => 8764.78,
]);
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": "GB123456789",
"tipo_documento": "06",
"nombre": "Example Clinical Ltd",
"direccion": "100 Long Avenue, Reading",
"cp": "RG2 6GP",
"pais_cliente": "GB",
"serie": "A2026",
"numero": "000158",
"simplificada": false,
"rectificativa": false,
"exportacion": true,
"tipo_operacion": "servicios",
"retencion": 0,
"lineas": [
{
"descripcion": "Estudio clínico — fase 2, centro 246",
"cantidad": 1,
"importe_unitario": 8764.78,
"tipo_iva": 0,
"tipo_req": 0
}
],
"total_factura": 8764.78
}
JSON
const datos = {
"fecha": "03/12/2026",
"hora": "10:30:00",
"nif": "GB123456789",
"tipo_documento": "06",
"nombre": "Example Clinical Ltd",
"direccion": "100 Long Avenue, Reading",
"cp": "RG2 6GP",
"pais_cliente": "GB",
"serie": "A2026",
"numero": "000158",
"simplificada": false,
"rectificativa": false,
"exportacion": true,
"tipo_operacion": "servicios",
"retencion": 0,
"lineas": [
{
"descripcion": "Estudio clínico — fase 2, centro 246",
"cantidad": 1,
"importe_unitario": 8764.78,
"tipo_iva": 0,
"tipo_req": 0
}
],
"total_factura": 8764.78
};
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": "GB123456789",
"tipo_documento": "06",
"nombre": "Example Clinical Ltd",
"direccion": "100 Long Avenue, Reading",
"cp": "RG2 6GP",
"pais_cliente": "GB",
"serie": "A2026",
"numero": "000158",
"simplificada": false,
"rectificativa": false,
"exportacion": true,
"tipo_operacion": "servicios",
"retencion": 0,
"lineas": [
{
"descripcion": "Estudio clínico — fase 2, centro 246",
"cantidad": 1,
"importe_unitario": 8764.78,
"tipo_iva": 0,
"tipo_req": 0
}
],
"total_factura": 8764.78
}
""")
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": "GB123456789",
"tipo_documento": "06",
"nombre": "Example Clinical Ltd",
"direccion": "100 Long Avenue, Reading",
"cp": "RG2 6GP",
"pais_cliente": "GB",
"serie": "A2026",
"numero": "000158",
"simplificada": false,
"rectificativa": false,
"exportacion": true,
"tipo_operacion": "servicios",
"retencion": 0,
"lineas": [
{
"descripcion": "Estudio clínico — fase 2, centro 246",
"cantidad": 1,
"importe_unitario": 8764.78,
"tipo_iva": 0,
"tipo_req": 0
}
],
"total_factura": 8764.78
}
""";
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": "DD6D4BDE60FE45A069B8D4981E36054ED5743341D12A84398A3DD93EA40A5F40",
"qr": "iVBORw0KGgo… (PNG en base64)",
"url": "https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR?nif=B89670855&numserie=A2026000158&fecha=03-12-2026&importe=8764.78"
},
"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».