New TicketBAI / Verifactu invoice
POST https://{entorno}.ticketbaiws.eus/tbai/
This method sends an invoice to the corresponding tax authority and returns the fingerprint, the QR code image in base64 and the invoice verification URL contained in the QR. The test environment submits to the test environment of the corresponding tax authority. It works with the three Basque provincial tax authorities and with the AEAT (Spanish Tax Agency) for Verifactu
Invoice resubmission: To correct or modify invoices that were reported with warnings or errors, make a new submission (with the corrected data) setting the ZUZENDU or SUBSANAR parameter to true.
(*) The series, number and total amount of the invoice cannot be modified; they must be the same as in the original invoice. (In Bizkaia, for invoices rejected by Batuz, the correction is sent through LROE subchapter 1.2 and keeps the fingerprint and QR of the original invoice; to change an invoice that has already been accepted, issue a corrective invoice)
Resending: invoice creation is idempotent. If an invoice that already exists (same date, series and number) is sent again, no new one is created: the original is returned and msg says so ("Previously sent on ..."). If it is resent with different data and without ZUZENDU, it is not duplicated either: the original is returned with the warning "Previously sent with different values ...". This makes it safe to retry an invoice creation after a timeout, a network error or a 429 response (honoring the Retry-After header).
PARAMETERS
| fecha string required Invoice issue date in dd/mm/yyyy format | 13/11/2021 | ||||||||||||||||
| hora string required Invoice issue time in HH:MM:SS format | 12:14:00 | ||||||||||||||||
| fecha_operacion string optional Transaction date in dd/mm/yyyy format | 12/11/2021 | ||||||||||||||||
| nif string required * NIF of the customer the invoice is issued to (*) Required only if simplificada is false. Optional for simplified invoices. | B01000012 | ||||||||||||||||
| tipo_documento string optional Type of identification document for foreign customers. Defaults to 02 for intra-EU invoices or 06 for the rest. Possible values: 02 => NIF-IVA (EU VAT number) 03 => Passport 04 => Official identity document issued by the country or territory of residence, 05 => Certificate of residence 06 => Other supporting document | 02 | ||||||||||||||||
| simplificada boolean required The invoice is a simplified invoice. If it is set as simplified, customer details are not required. | true | ||||||||||||||||
| pais_cliente string optional 2-letter country code of the customer if the customer's NIF is foreign (ISO-3166 Alpha-2 code format) | ES | ||||||||||||||||
| nombre string required * Legal name of the customer the invoice is issued to (*) Required only if simplificada is false. Optional for simplified invoices. | Example Company S.L. | ||||||||||||||||
| direccion string required * Billing address of the customer the invoice is issued to (*) Required only in Álava and Gipuzkoa | 123 Example Street | ||||||||||||||||
| cp string required * Postal code of the customer the invoice is issued to (*) Required only in Álava and Gipuzkoa | 01013 | ||||||||||||||||
| poblacion string recommended Town/municipality of the customer the invoice is issued to (*) It will be required for invoices to companies and professionals established in Spain that are sent to the AEAT's SPFE (Spanish public B2B e-invoicing platform) under the Crea y Crece law. If it is missing, the response includes a warning in msg. | Vitoria-Gasteiz | ||||||||||||||||
| provincia string optional Customer's province. If not provided, it is derived from the postal code for invoices to customers in Spain. | Álava | ||||||||||||||||
| serie string required Invoice series. | A | ||||||||||||||||
| numero string required Invoice number | 2021000123 | ||||||||||||||||
| rectificativa boolean required The invoice is a corrective invoice | false | ||||||||||||||||
| clave_rectificativa string optional Corrective invoice code (R1, R2, R3, R4, R5). If not set, R1 is used, or R5 if it is a simplified invoice | R1 | ||||||||||||||||
| tipo_rectificativa string optional Corrective invoice type: (S) by substitution (I) by differences. If not set, it is interpreted as I (by differences). The value "SN" is available for corrective invoices by substitution without providing the ImporteRectificacionSustitutiva block | I | ||||||||||||||||
rectificadas object array required if rectificativa
| |||||||||||||||||
| tipo_operacion string optional Transaction type: servicios (services) or bienes (goods). If not set, the transaction is treated as servicios | servicios | ||||||||||||||||
| intracomunitaria boolean optional The invoice is an intra-EU invoice | false | ||||||||||||||||
| exportacion boolean optional The invoice is an export outside the EU | false | ||||||||||||||||
| retencion float required Withholding amount applied | 0.00 | ||||||||||||||||
| lineas object array. MAX 1000 lines required * (*) Verifactu and Bizkaia do not require the detail of each invoice line, but they do require the overall tax bases
| |||||||||||||||||
| total_factura float required Invoice total amount | 132.00 | ||||||||||||||||
| zuzendu boolean optional Modification or resubmission of an invoice that previously returned an error. In Bizkaia it applies to invoices rejected by Batuz: it is sent through LROE subchapter 1.2 and keeps the original fingerprint and QR. To change an invoice that has already been accepted, issue a corrective invoice. | false | ||||||||||||||||
| regimen_iva integer optional Special VAT regime code | 17 |
| causa_exencion string optional VAT exemption reason code. If not set, the application will determine the most appropriate one Options: E1: Domestic transactions (Article 20 of the VAT Law) E2: Exports of goods (Article 21 of the VAT Law) E3: Exports (ships, fishing...) (Article 22 of the VAT Law) E4: Free zones, free warehouses and customs regimes (Articles 23 and 24 of the VAT Law) E5: Intra-EU transactions (Article 25 of the VAT Law) E6: Exempt for another reason RL: Not subject under place-of-supply rules OT: Other reasons for not being subject (Article 7 of the VAT Law) IE: Not subject under place-of-supply rules but foreign tax, IPSI/IGIC or VAT is charged VT: Not subject, sales made on behalf of third parties (amount not counted for VAT or IRPF purposes) (*) Exemption reasons not available for Verifactu | E6 |
| inversion_sujeto_pasivo boolean optional Invoice with reverse charge | false |
| emitida_terceros string optional Invoice issued by a third party or by the recipient. Possible values: N(no), T(third party), D(recipient) | N |
| modo_recargo_equivalencia boolean optional Transaction under the equivalence surcharge scheme | false |
| modo_regimen_simplificado boolean optional Transaction under the simplified VAT scheme | false |
| epigrafe string optional IAE activity code for the invoice. If not provided, the activity code set in the company profile will be sent. This parameter is only valid for individuals (natural persons) who must send TicketBAI to Bizkaia Batuz and work under more than one activity code. | 165960 |
$ curl --request POST \
--url https://api-test.ticketbaiws.eus/tbai/ \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Token: xxx' \
--header 'Nif: 00000014Z'
--data '
{
"fecha": "13\/11\/2021",
"hora": "12:14:00",
"fecha_operacion": "12\/11\/2021",
"pais_cliente": "ES",
"nif": "B00000011",
"nombre": "Empresa de ejemplo S.L.",
"direccion": "Calle Falsa 123",
"cp": "28080",
"poblacion": "Madrid",
"provincia": "Madrid",
"serie": "A",
"numero": "2021000123",
"simplificada": false,
"rectificativa": false,
"clave_rectificativa": "R1",
"tipo_rectificativa": "I",
"rectificadas" : [
{
"serie": "A"
"numero": "20210000075",
"fecha": "10\/11\/2021"
}
],
"tipo_operacion": "servicios",
"intracomunitaria": false,
"exportacion": false,
"retencion": 0,
"lineas": [
{
"descripcion": "Producto normal",
"cantidad": 1,
"importe_unitario": 100.00,
"tipo_iva": 21.00,
"tipo_req": 0
},
{
"descripcion": "Producto alimentario",
"cantidad": 1,
"importe_unitario": 10,
"tipo_iva": 10.00,
"tipo_req": 0
}
],
"total_factura": 132.00,
"zuzendu" : false
}'
$ composer require ticketbaiws/ticketbaiws-php
<?php
// Installation: composer require ticketbaiws/ticketbaiws-php
require 'vendor/autoload.php';
$tbai = new \TicketbaiWS\Client('xxx', '00000014Z', ['entorno' => 'test']);
$r = $tbai->crearFactura([
'fecha' => '13/11/2021',
'hora' => '12:14:00',
'fecha_operacion' => '12/11/2021',
'nif' => 'B00000011',
'nombre' => 'Empresa de ejemplo S.L.',
'direccion' => 'Calle Falsa 123',
'cp' => '28080',
'poblacion' => 'Madrid',
'provincia' => 'Madrid',
'serie' => 'A-',
'numero' => '2021000123',
'simplificada' => false,
'rectificativa' => false,
'tipo_operacion' => 'servicios',
'intracomunitaria' => false,
'retencion' => 0,
'lineas' => [
['descripcion' => 'Producto normal', 'cantidad' => 1, 'importe_unitario' => 100.0, 'tipo_iva' => '21.00', 'tipo_req' => 0],
['descripcion' => 'Producto alimentario', 'cantidad' => 1, 'importe_unitario' => 10, 'tipo_iva' => 10.0, 'tipo_req' => 0],
],
'total_factura' => 132.0,
'zuzendu' => false,
]);
if ($r->isError()) {
echo $r->getMessageText();
} else {
// huella_tbai (TicketBAI) o huella (Verifactu), qr (PNG en base64) y url
print_r($r->getData());
}
$ python -m pip install requests
import requests
url = "https://api-test.ticketbaiws.eus/tbai/"
payload = {
"fecha": "13\/11\/2021",
"hora": "12:14:00",
"fecha_operacion":"12\/11\/2021",
"nif": "B00000011",
"nombre": "Empresa de ejemplo S.L.",
"direccion": "Calle Falsa 123",
"cp": "28080",
"poblacion": "Madrid",
"provincia": "Madrid",
"serie": "A-",
"numero": "2021000123",
"simplificada": false,
"rectificativa": false,
"tipo_operacion":"servicios",
"intracomunitaria": false,
"retencion": 0,
"lineas": [
{
"descripcion": "Producto normal",
"cantidad": 1,
"importe_unitario": 100.00,
"tipo_iva": 21.00,
"tipo_req": 0
},
{
"descripcion": "Producto alimentario",
"cantidad": 1,
"importe_unitario": 10,
"tipo_iva": 10.00,
"tipo_req": 0
}
],
"total_factura": 132.00,
"zuzendu":false
}
headers = {"Accept": "application/json", "Token" : "xxx", "Nif" : "00000014Z"}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api-test.ticketbaiws.eus/tbai/");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, '{"fecha":"13\/11\/2021","hora":"12:14:00","fecha_operacion":"12\/11\/2021","nif":"B00000011","nombre":"Empresa de ejemplo S.L.","direccion":"Calle Falsa 123","cp":"28080","poblacion":"Madrid","provincia":"Madrid","serie":"A-","numero":"2021000123","simplificada":false,"rectificativa":false,"tipo_operacion":"servicios","intracomunitaria":false,"retencion":0,"lineas":[{"descripcion":"Producto normal","cantidad":1,"importe_unitario":100.00,"tipo_iva":"21.00","tipo_req":0},{"descripcion":"Producto alimentario","cantidad":1,"importe_unitario":10,"tipo_iva":10.00,"tipo_req":0}],"total_factura":132.00,"zuzendu":false}');
CURLcode ret = curl_easy_perform(hnd);
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, '{"fecha":"13\/11\/2021","hora":"12:14:00","fecha_operacion":"12\/11\/2021","nif":"B00000011","nombre":"Empresa de ejemplo S.L.","direccion":"Calle Falsa 123","cp":"28080","poblacion":"Madrid","provincia":"Madrid","serie":"A-","numero":"2021000123","simplificada":false,"rectificativa":false,"tipo_operacion":"servicios","intracomunitaria":false,"retencion":0,"lineas":[{"descripcion":"Producto normal","cantidad":1,"importe_unitario":100.00,"tipo_iva":"21.00","tipo_req":0},{"descripcion":"Producto alimentario","cantidad":1,"importe_unitario":10,"tipo_iva":10.00,"tipo_req":0}],"total_factura":132.00,"zuzendu":false}');
Request request = new Request.Builder()
.url("https://api-test.ticketbaiws.eus/tbai/")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("Token", "xxx")
.addHeader("Nif", "00000014Z")
.build();
Response response = client.newCall(request).execute();
HTTP/1.1 200 OK
{
"result": "OK",
"return": {
"huella_tbai" : "TBAI-B01000012-131121-zG3wtCW3WlOSN-108",
"qr" : "iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAIAAABEtEjdAAAABmJ...",
"url" : "https://batuz.eus/QRTBAI/?id=TBAI-..."
},
"msg": null
}
HTTP/1.1 200 OK
{
"result": "OK",
"return": {
"huella" : "8FA696A615A750A9EC04A273013F05EB1B092076FFD9A66EF6",
"qr" : "iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAIAAABEtEjdAAAABmJ...",
"url" : "https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR?..."
},
"msg": null
}
HTTP/1.1 200 OK
{
"result": "OK",
"return": {
"huella" : "8FA696A615A750A9EC04A273013F05EB1B092076FFD9A66EF6",
"qr" : "iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAIAAABEtEjdAAAABmJ...",
"url" : "https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR?..."
},
"msg": "poblacion: customer town/city is missing. It will be mandatory for B2B invoices sent to the AEAT e-invoicing public solution (SPFE, Ley Crea y Crece)"
}
TicketBAI / Verifactu methods
- POST New invoice / resubmission (zuzendu) TicketBAI / Verifactu
- POST Complete a simplified invoice
- GET Get a TicketBAI / Verifactu invoice
- GET List TicketBAI / Verifactu invoices
- GET Download TicketBAI / Verifactu XML
- GET Download invoice in FacturaE format
- GET Download invoice as PDF
- GET System status
- DEL Cancel a TicketBAI / Verifactu invoice
- PUT Force TicketBAI / Verifactu resend
- POST Validate a NIF with the AEAT
- POST Validate a VAT number in VIES
Representation document
- GET Representation document - Download template
- POST Representation document - Upload document
- GET Representation document - Download uploaded document
- DELETE Representation document - Revoke uploaded document
BATUZ BIZKAIA specific methods
- GET List IAE activity codes
- POST LROE - Received invoices - Submit (BATUZ)
- PUT LROE - Received invoices - Update (BATUZ)
- GET LROE - Received invoices - Query (BATUZ)
- DEL LROE - Received invoices - Cancel (BATUZ)
- POST LROE - Expenses without invoice - Submit (BATUZ, form 140)
- PUT LROE - Expenses without invoice - Update (BATUZ, form 140)
- GET LROE - Expenses without invoice - Query (BATUZ, form 140)
- DEL LROE - Expenses without invoice - Cancel (BATUZ, form 140)
- POST LROE - Cash accounting COLLECTIONS - Submit (BATUZ)
- PUT LROE - Cash accounting COLLECTIONS - Update (BATUZ)
- GET LROE - Cash accounting COLLECTIONS - Query (BATUZ)
- DEL LROE - Cash accounting COLLECTIONS - Cancel (BATUZ)
- POST LROE - Cash accounting PAYMENTS - Submit (BATUZ)
- PUT LROE - Cash accounting PAYMENTS - Update (BATUZ)
- GET LROE - Cash accounting PAYMENTS - Query (BATUZ)
- DEL LROE - Cash accounting PAYMENTS - Cancel (BATUZ)
SII (AEAT)
Customers and products (invoicing tool)
- GET Customers - Search / get customers
- POST Customers - New customer
- PUT Customers - Update customer
- GET Products - Search / get products
