> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.invoice-api.xhub.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.invoice-api.xhub.io/_mcp/server.

# Generate VeriFactu QR (ES)

POST https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr
Content-Type: application/json

Generate the AEAT VeriFactu QR for a Spanish invoice. Returns the verification URL plus PNG (base64) and SVG renderings of the QR code.

Note: PNG is base64-encoded (no `data:` prefix) so clients can embed it directly or decode it to bytes — JSON keeps the response easy to consume without multipart.

Send `environment: "production"` when your invoicing system reports its records to the AEAT (VERI*FACTU); `environment: "test"` gives the AEAT test environment. Omitted: the QR points at the AEAT host of the configured VERI*FACTU endpoint; when VERI*FACTU is not active on this service there is no production host and the call answers 501 `VERIFACTU_QR_NO_PRODUCTION_HOST`. `environment` in the response says which host the QR points at, `legend` is the phrase to print below the QR. invoice-api does not report the invoice to the AEAT.

Only VERI*FACTU QR codes are built. A system that does not report its records needs the `ValidarQRNoVerifactu` URL of the AEAT QR specification §5.2; this endpoint does not serve it.

Reference: https://docs.invoice-api.xhub.io/api-reference/verifactu/qr

## Authentication

- `Authorization` header (bearer token, required) — API Key authentication. Use `sk_live_*` for production or `sk_test_*` for testing.

## Servers

- `https://service.invoice-api.xhub.io` (Invoice API v1 (production), default)
- `/` (Diese Instanz (lokale Entwicklung))

## Request

### Body (application/json)

This endpoint expects an object.

- `sellerNif` (string, required) — Seller NIF/CIF (Spanish tax ID), e.g., "B12345678".
- `invoiceDate` (string, required) — Invoice issue date in AEAT QR format `DD-MM-YYYY`.
- `total` (double, required) — Invoice total amount used as the `importe` query parameter. Negative totals are accepted for credit notes.
- `numSerieFactura` (string, optional) — Exactly the `NumSerieFactura` (series + number) your system reported to the AEAT for this invoice. It goes into the `numserie` parameter unchanged (AEAT QR specification v0.5.0 §6: up to 60 characters, ASCII 32–126; URL-encoded by the QR builder). Send either `numSerieFactura` or `invoiceSeries` + `invoiceNumber`, not both.
- `invoiceSeries` (string, optional) — Older form: invoice series, joined with `invoiceNumber` as `series/number` into the `numserie` parameter (e.g. `A` + `2026-0042` ⇒ `A/2026-0042`). This only matches the AEAT record if your system reported the number in exactly that form — otherwise send `numSerieFactura`. Optional: without a series `numserie` is `invoiceNumber` alone.
- `invoiceNumber` (string, optional) — Older form: invoice number (with `invoiceSeries`, see there). Required unless `numSerieFactura` is sent.
- `environment` (enum, optional) — Which AEAT verification service the QR points at (QR specification v0.5.0 §5.1, `ValidarQR`). `test`: AEAT test environment (`prewww2.aeat.es`). `production`: AEAT production (`www2.agenciatributaria.gob.es`); send it when **your** invoicing system reports its records to the AEAT (VERI*FACTU). Omitted: the QR points at the host of the configured VERI*FACTU endpoint; when VERI*FACTU is not active on this service there is no production host, and the call answers 501 `VERIFACTU_QR_NO_PRODUCTION_HOST`. Only VERI*FACTU QR codes are built: a system that does not report its records needs the `ValidarQRNoVerifactu` URL of QR specification §5.2, which this endpoint does not serve.
  - Allowed values: `test`, `production`
- `verifactuMode` (boolean, optional, deprecated) — Deprecated and ignored. The platform is VERI*FACTU-only (`TipoUsoPosibleSoloVerifactu='S'`), so the QR always points at the `ValidarQR` cotejo service. Whether that is the AEAT test or production host follows the deployment configuration (`GOV_API_ES_AEAT_URL`), not this flag. Accepted for backwards compatibility; will be removed.

## Response

### 200

QR generated successfully

- `url` (string, required) — AEAT verification URL embedded in the QR code.
- `png` (string, required) — Base64-encoded PNG image of the QR code (no data URL prefix).
- `svg` (string, required) — SVG markup string for the QR code.
- `environment` (enum, required) — Which AEAT verification service the QR code points at.
  - Allowed values: `test`, `production`
- `legend` (string, required) — The phrase that must appear directly below the QR code on an invoice from a VERI*FACTU system (Orden HAC/1177/2024 art. 20.1.b). The order also allows the short form "VERI*FACTU".

## Errors

### 400 Bad Request Error

Bad Request - Invalid input

- `PostApiV1InvoiceEsVerifactuQrRequestBadRequestError`
  - ErrorResponse: ErrorResponse
  - RequestValidationError: RequestValidationError

### 401 Unauthorized Error

Unauthorized - Invalid or missing API key

- `error` (string, required) — Error code
- `message` (string, required) — Human-readable error message
- `code` (string, optional) — Machine-readable reason, where one exists — e.g. `UNSUPPORTED_FORMAT_VERSION`, `UNSUPPORTED_FORMAT_PROFILE`, `CONFLICTING_FORMAT_OPTIONS`
- `field` (string, optional) — The request field the error refers to, where one exists

### 403 Forbidden Error

Forbidden - Missing required entitlement

- `error` (string, required) — Error code
- `message` (string, required) — Human-readable error message
- `code` (string, optional) — Machine-readable reason, where one exists — e.g. `UNSUPPORTED_FORMAT_VERSION`, `UNSUPPORTED_FORMAT_PROFILE`, `CONFLICTING_FORMAT_OPTIONS`
- `field` (string, optional) — The request field the error refers to, where one exists

### 500 Internal Server Error

Internal Server Error

- `error` (string, required) — Error code
- `message` (string, required) — Human-readable error message
- `code` (string, optional) — Machine-readable reason, where one exists — e.g. `UNSUPPORTED_FORMAT_VERSION`, `UNSUPPORTED_FORMAT_PROFILE`, `CONFLICTING_FORMAT_OPTIONS`
- `field` (string, optional) — The request field the error refers to, where one exists

### 501 Not Implemented Error

VERI*FACTU is not active on this service and no `environment` was sent — code `VERIFACTU_QR_NO_PRODUCTION_HOST`. Not retryable.

- `error` (string, required) — Error code
- `message` (string, required) — Human-readable error message
- `code` (string, optional) — Machine-readable reason, where one exists — e.g. `UNSUPPORTED_FORMAT_VERSION`, `UNSUPPORTED_FORMAT_PROFILE`, `CONFLICTING_FORMAT_OPTIONS`
- `field` (string, optional) — The request field the error refers to, where one exists

## Types

### ErrorResponse

- `error` (string, required) — Error code
- `message` (string, required) — Human-readable error message
- `code` (string, optional) — Machine-readable reason, where one exists — e.g. `UNSUPPORTED_FORMAT_VERSION`, `UNSUPPORTED_FORMAT_PROFILE`, `CONFLICTING_FORMAT_OPTIONS`
- `field` (string, optional) — The request field the error refers to, where one exists

### RequestValidationError

The request body failed the input check. `error` lists every finding; each names the field (`path`) and the rule (`code`). Depending on the code, a finding also carries the limit (`maximum`, `minimum`), the expected type (`expected`), the allowed values (`values`) or the unknown keys (`keys`).

- `success` (false, required)
- `error` (list of RequestValidationErrorErrorItems, required)

### RequestValidationErrorErrorItems

- `code` (string, required) — Rule that failed, e.g. `too_big`, `invalid_type`, `invalid_value`.
- `path` (list of RequestValidationErrorErrorItemsPathItems, required) — Path of the field in the request body, e.g. `["invoice", "seller", "name"]`.
- `message` (string, required)
- `maximum` (double, optional)
- `minimum` (double, optional)
- `inclusive` (boolean, optional)
- `origin` (string, optional)
- `expected` (string, optional)
- `values` (list of any, optional)
- `keys` (list of string, optional)
- `format` (string, optional)

### RequestValidationErrorErrorItemsPathItems

- string
- double

## Examples

**Request**

```json
{
  "sellerNif": "B12345678",
  "invoiceDate": "20-03-2026",
  "total": 5712
}
```

**Response**

```json
{
  "url": "https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR?nif=B12345678&numserie=A%2F2026-0042&fecha=20-03-2026&importe=5712.00",
  "png": "iVBORw0KGgoAAAANSUhEUgAA...",
  "svg": "<svg ...>...</svg>",
  "environment": "production",
  "legend": "Factura verificable en la sede electrónica de la AEAT"
}
```

**SDK Code**

```python
import requests

url = "https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr"

payload = {
    "sellerNif": "B12345678",
    "invoiceDate": "20-03-2026",
    "total": 5712
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"sellerNif":"B12345678","invoiceDate":"20-03-2026","total":5712}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr"

	payload := strings.NewReader("{\n  \"sellerNif\": \"B12345678\",\n  \"invoiceDate\": \"20-03-2026\",\n  \"total\": 5712\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"sellerNif\": \"B12345678\",\n  \"invoiceDate\": \"20-03-2026\",\n  \"total\": 5712\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"sellerNif\": \"B12345678\",\n  \"invoiceDate\": \"20-03-2026\",\n  \"total\": 5712\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr', [
  'body' => '{
  "sellerNif": "B12345678",
  "invoiceDate": "20-03-2026",
  "total": 5712
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"sellerNif\": \"B12345678\",\n  \"invoiceDate\": \"20-03-2026\",\n  \"total\": 5712\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "sellerNif": "B12345678",
  "invoiceDate": "20-03-2026",
  "total": 5712
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://service.invoice-api.xhub.io/api/v1/invoice/es/verifactu-qr")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```