> 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.

# Export the registro chain of one NIF (ES, art. 14)

GET https://service.invoice-api.xhub.io/api/v1/verifactu/chain/{vatId}/export

Hands out every registro of the chain belonging to `vatId` as ONE json document, as required by art. 14 RD 1007/2023: the obligado tributario must be able to produce the records for an inspection. Each entry carries the frozen `registro` next to its `huella`, so the hash can be recomputed by the recipient — the registro is passed through unchanged, never reshaped. Scoped to the organisation behind the API key: a chain owned by someone else is not visible and comes back as an empty export. Optional `from`/`to` (ISO-8601) narrow the range by entry timestamp; above 5000 entries a range is mandatory and the error says so.

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

## 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

### Path parameters

- `vatId` (string, required)

### Query parameters

- `from` (datetime, optional) — Only entries appended at or after this ISO-8601 instant. Mandatory together with or instead of `to` once the chain exceeds the export limit.
- `to` (datetime, optional) — Only entries appended at or before this ISO-8601 instant.

## Response

### 200

The chain, ordered by sequence number

- `vatId` (string, required) — NIF whose chain this is — the chain key.
- `exportedAt` (string, required) — ISO-8601 timestamp of THIS export, not of the last entry.
- `from` (string, required, nullable) — Lower bound of the exported range, or null.
- `to` (string, required, nullable) — Upper bound of the exported range, or null.
- `entryCount` (integer, required) — Number of entries in `entries`.
- `entries` (list of ApiV1VerifactuChainVatIdExportGetResponsesContentApplicationJsonSchemaEntriesItems, required)

## Errors

### 400 Bad Request Error

Either `from`/`to` is not a valid ISO-8601 date, or the chain is too large to export without a range — the message names the entry count

- `any`

### 401 Unauthorized Error

Missing or invalid API key, or the key has no organisation

- `any`

## Types

### ApiV1VerifactuChainVatIdExportGetResponsesContentApplicationJsonSchemaEntriesItems

- `sequenceNumber` (integer, required) — Position in the chain (1-based, gapless).
- `invoiceId` (string, required) — Internal id of the invoice this entry belongs to.
- `invoiceNumber` (string, required, nullable) — Invoice number as issued, or null if the entry predates numbering.
- `huella` (string, required) — The entry hash (huella) as stored — recompute it from `registro`.
- `previousHuella` (string, required) — Huella of the preceding entry; empty string for the first entry of the chain.
- `recordType` (string, required, nullable) — ALTA (issuance) or ANULACION (cancellation), as recorded.
- `createdAt` (string, required) — ISO-8601 timestamp the entry was appended to the chain.
- `registro` (map from string to any, required, nullable) — The frozen registro exactly as it was submitted to the AEAT — the object the huella is computed over. Not reshaped.
- `status` (string, required, nullable) — Submission state of the matching queue row (ACCEPTED, PENDING, …), or null.
- `resultCsv` (string, required, nullable) — The AEAT CSV once the registro was accepted.
- `lastError` (string, required, nullable) — Last submission error for this entry, verbatim.

## Examples

**Response**

```json
{
  "vatId": "string",
  "exportedAt": "string",
  "from": "string",
  "to": "string",
  "entryCount": 1,
  "entries": [
    {
      "sequenceNumber": 1,
      "invoiceId": "string",
      "invoiceNumber": "string",
      "huella": "string",
      "previousHuella": "string",
      "recordType": "string",
      "createdAt": "string",
      "registro": {},
      "status": "string",
      "resultCsv": "string",
      "lastError": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	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/verifactu/chain/vatId/export")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

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.get("https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://service.invoice-api.xhub.io/api/v1/verifactu/chain/vatId/export")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```