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

# Store a PDF template

POST https://service.invoice-api.xhub.io/api/v1/pdf/templates
Content-Type: application/json

Stores a BlockTemplate for the organization of the API key and returns it with its `id`. Use the `id` as `templateId` in `POST /pdf/generate` or in `formatOptions.templateId` of the invoice routes. The template appears in the Console under PDF templates. `isDefault: true` makes it the default template of the whole organization: every other template of the organization loses the default. Requires an API key with `pdf:template:create` and purpose `user`; session keys get 403 `SESSION_KEY_FORBIDDEN`. Not metered.

Reference: https://docs.invoice-api.xhub.io/api-reference/pdf/post-api-v-1-pdf-templates

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

- `name` (string, required)
- `template` (map from string to any, required)
- `description` (string, optional)
- `documentType` (string, optional, default: invoice)
- `sampleData` (map from string to any, optional)
- `pageSettings` (map from string to any, optional)
- `isDefault` (boolean, optional, default: false)

## Response

### 201

Template stored

- `id` (string, required) — Template id — use it as `templateId` in `POST /pdf/generate`.
- `organizationId` (string, required)
- `name` (string, required)
- `description` (string, required, nullable)
- `documentType` (string, required)
- `version` (string, required)
- `template` (map from string to any, required) — The stored BlockTemplate.
- `sampleData` (map from string to any, required, nullable)
- `pageSettings` (map from string to any, required, nullable)
- `isDefault` (boolean, required, nullable)
- `isActive` (boolean, required, nullable)
- `countryCode` (string, required, nullable)
- `isSystem` (boolean, required)
- `createdAt` (datetime, required)
- `createdBy` (string, required) — `api-key:<key name>` for templates stored through this API.
- `updatedAt` (datetime, required)
- `updatedBy` (string, required)

## Errors

### 400 Bad Request Error

Invalid input — `{ error: [Zod issues with path], success: false }`, without an echo of the request

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

### 401 Unauthorized Error

Unauthorized — missing or invalid 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 — `FORBIDDEN` (the key lacks the entitlement named in `message`) or `SESSION_KEY_FORBIDDEN` (session keys cannot use the template routes)

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

### 413 Content Too Large Error

Payload Too Large — `PAYLOAD_TOO_LARGE`: the request body exceeds 2 MiB (2097152 bytes); `limit` names the number

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

## Types

### 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
{
  "name": "string"
}
```

**Response**

```json
{
  "id": "string",
  "organizationId": "string",
  "name": "string",
  "description": "string",
  "documentType": "string",
  "version": "string",
  "template": {},
  "sampleData": {},
  "pageSettings": {},
  "isDefault": true,
  "isActive": true,
  "countryCode": "string",
  "isSystem": true,
  "createdAt": "2024-01-15T09:30:00Z",
  "createdBy": "string",
  "updatedAt": "2024-01-15T09:30:00Z",
  "updatedBy": "string"
}
```

**SDK Code**

```python
import requests

url = "https://service.invoice-api.xhub.io/api/v1/pdf/templates"

payload = { "name": "string" }
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/pdf/templates';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"string"}'
};

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/pdf/templates"

	payload := strings.NewReader("{\n  \"name\": \"string\"\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/pdf/templates")

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  \"name\": \"string\"\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/pdf/templates")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"string\"\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/pdf/templates', [
  'body' => '{
  "name": "string"
}',
  '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/pdf/templates");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["name": "string"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://service.invoice-api.xhub.io/api/v1/pdf/templates")! 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()
```