# PDF templates

> Markdown edition of https://api.fiz.co/docs/api/pdf-templates. Português: https://api.fiz.co/docs/api/pdf-templates.md?lang=pt. Index: https://api.fiz.co/llms.txt

The layouts documents are printed with: list, export, check, preview, install and remove. 10 operations.

## List templates

GET `/templates`

Lists the PDF templates. A partner application sees only the templates it installed; an API key sees the account's templates.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `kind` | query | string | Kind of templates to list. Invoice templates by default; TRANSPORT\_DOCUMENT lists transport document ones. — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `fiscal` | query | boolean | Fiscal templates by default; false lists the non-fiscal ones (auxiliary prints). |

**curl**

```shell
curl 'https://api.fiz.co/templates' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.list();
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.list()
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->list();
```

### Response `200`

List of templates returned successfully

| Field | Type | Description |
| --- | --- | --- |
| `[].id` | string | Unique template identifier |
| `[].name` | string | Template name |
| `[].cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `[].language` | string | Template language — One of: `en`, `pt` |
| `[].kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `[].format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `[].fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `[].contractVersion` | number | Data contract version the template needs |
| `[].updatedAt` | string | Last change |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Import template

POST `/templates`

Creates a template from an export. Created by a partner application, the template belongs to that application: only it sees and changes it, and it prints only the documents that application issued, when templateId is given on the PDF download. An application can keep up to 5 templates per company.

Authentication: an API key (`x-api-key`) or an OAuth access token. Send an `Idempotency-Key` to retry this call safely.

### Request body

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `kind` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `format` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `fiscal` | boolean | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `documentTypes` | string\[\] | On import of a template without starterId: if it includes CREDIT\_NOTE or DEBIT\_NOTE, asks that the template print credit and debit notes. Granted only if the template prints the reference to the rectified document. Ignored with starterId and on replace. |
| `updatedAt` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `name` **required** | string | Template name, unique among the templates of the same owner |
| `data` **required** | object | The template (the data field of GET /templates/{id}, or written from the published description). Validated on the server; an unknown field or a missing fiscal rule is refused with 400. |
| `contractVersion` **required** | number | Data contract version the template was made for (contractVersion from the export). A template that needs a higher version than the one given is refused. |
| `cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `language` | string | Template language. Defaults to pt. — One of: `en`, `pt` |
| `starterId` | string | Starter (starterId from the export). Sets the kind, the paper and whether the template is fiscal; without it the template is a fiscal A4 invoice template. |

**curl**

```shell
# Once per operation. Keep it and reuse it on every retry.
IDEMPOTENCY_KEY=$(uuidgen)
```

```shell
curl --request POST 'https://api.fiz.co/templates' \
  --header "x-api-key: $FIZ_API_KEY" \
  --header 'Content-Type: application/json' \
  --header "Idempotency-Key: ${IDEMPOTENCY_KEY:?set the operation key first, in the step above}" \
  --data '{
  "name": "Modelo Ginásio",
  "data": {
    "basePdf": {
      "width": 210,
      "height": 297,
      "padding": [
        12,
        12,
        12,
        12
      ]
    },
    "schemas": [
      [
        {
          "name": "invoice",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "number"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "customer",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "profile",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "number",
          "type": "text",
          "readOnly": true,
          "content": "{invoice.type} {invoice.number}",
          "position": {
            "x": 12,
            "y": 60
          },
          "width": 186,
          "height": 12,
          "fontName": "Roboto Bold",
          "fontSize": 24
        },
        {
          "name": "items",
          "type": "table",
          "rowSource": "items",
          "columns": [
            "{item.nameWithDescription}",
            "{item.quantity}",
            "{item.unitPrice}",
            "{item.taxRate}",
            "{item.lineTotal}"
          ],
          "head": [
            "Descrição",
            "Qtd.",
            "Preço",
            "IVA",
            "Total"
          ],
          "headWidthPercentages": [
            46,
            10,
            16,
            10,
            18
          ],
          "showHead": true,
          "tableStyles": {
            "borderWidth": 0,
            "borderColor": "#000000"
          },
          "headStyles": {
            "fontName": "Roboto Bold",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "top",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 5,
              "right": 0,
              "bottom": 5,
              "left": 1
            }
          },
          "bodyStyles": {
            "fontName": "Roboto",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "middle",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "alternateBackgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 3,
              "right": 0,
              "bottom": 2,
              "left": 1
            }
          },
          "columnStyles": {
            "alignment": {
              "0": "left",
              "1": "left",
              "2": "right",
              "3": "right",
              "4": "right"
            }
          },
          "position": {
            "x": 12,
            "y": 85
          },
          "width": 186,
          "height": 40
        }
      ]
    ]
  },
  "contractVersion": 2
}'
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.create({
  name: 'Modelo Ginásio',
  data: {
    basePdf: {
      width: 210,
      height: 297,
      padding: [
        12,
        12,
        12,
        12,
      ],
    },
    schemas: [
      [
        {
          name: 'invoice',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'number',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'customer',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'profile',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'number',
          type: 'text',
          readOnly: true,
          content: '{invoice.type} {invoice.number}',
          position: {
            x: 12,
            y: 60,
          },
          width: 186,
          height: 12,
          fontName: 'Roboto Bold',
          fontSize: 24,
        },
        {
          name: 'items',
          type: 'table',
          rowSource: 'items',
          columns: [
            '{item.nameWithDescription}',
            '{item.quantity}',
            '{item.unitPrice}',
            '{item.taxRate}',
            '{item.lineTotal}',
          ],
          head: [
            'Descrição',
            'Qtd.',
            'Preço',
            'IVA',
            'Total',
          ],
          headWidthPercentages: [
            46,
            10,
            16,
            10,
            18,
          ],
          showHead: true,
          tableStyles: {
            borderWidth: 0,
            borderColor: '#000000',
          },
          headStyles: {
            fontName: 'Roboto Bold',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'top',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 5,
              right: 0,
              bottom: 5,
              left: 1,
            },
          },
          bodyStyles: {
            fontName: 'Roboto',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'middle',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            alternateBackgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 3,
              right: 0,
              bottom: 2,
              left: 1,
            },
          },
          columnStyles: {
            alignment: {
              '0': 'left',
              '1': 'left',
              '2': 'right',
              '3': 'right',
              '4': 'right',
            },
          },
          position: {
            x: 12,
            y: 85,
          },
          width: 186,
          height: 40,
        },
      ],
    ],
  },
  contractVersion: 2,
});
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.create({
    "name": "Modelo Ginásio",
    "data": {
        "basePdf": {
            "width": 210,
            "height": 297,
            "padding": [
                12,
                12,
                12,
                12,
            ],
        },
        "schemas": [
            [
                {
                    "name": "invoice",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "number",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "customer",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "profile",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "number",
                    "type": "text",
                    "readOnly": True,
                    "content": "{invoice.type} {invoice.number}",
                    "position": {
                        "x": 12,
                        "y": 60,
                    },
                    "width": 186,
                    "height": 12,
                    "fontName": "Roboto Bold",
                    "fontSize": 24,
                },
                {
                    "name": "items",
                    "type": "table",
                    "rowSource": "items",
                    "columns": [
                        "{item.nameWithDescription}",
                        "{item.quantity}",
                        "{item.unitPrice}",
                        "{item.taxRate}",
                        "{item.lineTotal}",
                    ],
                    "head": [
                        "Descrição",
                        "Qtd.",
                        "Preço",
                        "IVA",
                        "Total",
                    ],
                    "headWidthPercentages": [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    "showHead": True,
                    "tableStyles": {
                        "borderWidth": 0,
                        "borderColor": "#000000",
                    },
                    "headStyles": {
                        "fontName": "Roboto Bold",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "top",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 5,
                            "right": 0,
                            "bottom": 5,
                            "left": 1,
                        },
                    },
                    "bodyStyles": {
                        "fontName": "Roboto",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "middle",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "alternateBackgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 3,
                            "right": 0,
                            "bottom": 2,
                            "left": 1,
                        },
                    },
                    "columnStyles": {
                        "alignment": {
                            "0": "left",
                            "1": "left",
                            "2": "right",
                            "3": "right",
                            "4": "right",
                        },
                    },
                    "position": {
                        "x": 12,
                        "y": 85,
                    },
                    "width": 186,
                    "height": 40,
                },
            ],
        ],
    },
    "contractVersion": 2,
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->create([
    'name' => 'Modelo Ginásio',
    'data' => [
        'basePdf' => [
            'width' => 210,
            'height' => 297,
            'padding' => [
                12,
                12,
                12,
                12,
            ],
        ],
        'schemas' => [
            [
                [
                    'name' => 'invoice',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'number',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'customer',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'profile',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'number',
                    'type' => 'text',
                    'readOnly' => true,
                    'content' => '{invoice.type} {invoice.number}',
                    'position' => [
                        'x' => 12,
                        'y' => 60,
                    ],
                    'width' => 186,
                    'height' => 12,
                    'fontName' => 'Roboto Bold',
                    'fontSize' => 24,
                ],
                [
                    'name' => 'items',
                    'type' => 'table',
                    'rowSource' => 'items',
                    'columns' => [
                        '{item.nameWithDescription}',
                        '{item.quantity}',
                        '{item.unitPrice}',
                        '{item.taxRate}',
                        '{item.lineTotal}',
                    ],
                    'head' => [
                        'Descrição',
                        'Qtd.',
                        'Preço',
                        'IVA',
                        'Total',
                    ],
                    'headWidthPercentages' => [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    'showHead' => true,
                    'tableStyles' => [
                        'borderWidth' => 0,
                        'borderColor' => '#000000',
                    ],
                    'headStyles' => [
                        'fontName' => 'Roboto Bold',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'top',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 5,
                            'right' => 0,
                            'bottom' => 5,
                            'left' => 1,
                        ],
                    ],
                    'bodyStyles' => [
                        'fontName' => 'Roboto',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'middle',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'alternateBackgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 3,
                            'right' => 0,
                            'bottom' => 2,
                            'left' => 1,
                        ],
                    ],
                    'columnStyles' => [
                        'alignment' => [
                            '0' => 'left',
                            '1' => 'left',
                            '2' => 'right',
                            '3' => 'right',
                            '4' => 'right',
                        ],
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 85,
                    ],
                    'width' => 186,
                    'height' => 40,
                ],
            ],
        ],
    ],
    'contractVersion' => 2,
]);
```

### Response `201`

Template created

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique template identifier |
| `name` | string | Template name |
| `cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `language` | string | Template language — One of: `en`, `pt` |
| `kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `starterId` | string | Editor starter this template was created from. Send it back when importing: it sets the template's kind, paper and whether it is fiscal. |
| `contractVersion` | number | Data contract version the template needs. Send it back when importing. |
| `documentTypes` | string\[\] | Document types the template prints |
| `data` | object | The template designed in the FIZ template editor (pdfme JSON with FIZ fields) |
| `updatedAt` | string | Last change |

### Errors

-   `400` Invalid template: unknown field, missing fiscal rule, insufficient contract version or template limit reached
-   `401` Unauthorized - API key missing or invalid
-   `409` A template with this name already exists
-   `422` The idempotency key was already used with a different request body
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Template fields

GET `/templates/fields`

The paths a template may reference, per data set. It is the list validation enforces: a path outside it is refused.

Authentication: an API key (`x-api-key`) or an OAuth access token.

**curl**

```shell
curl 'https://api.fiz.co/templates/fields' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.fields();
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.fields()
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->fields();
```

### Response `200`

Fields per data set

| Field | Type | Description |
| --- | --- | --- |
| `[].dataSet` | string | Data set: fiscal (invoices and related documents), nonFiscal (auxiliary print) or transport (transport documents) |
| `[].fields` | string\[\] | Paths a text field or a cell may reference, such as {invoice.number} |
| `[].rowFields` | string\[\] | Paths a row of a table bound to the document lines may reference |
| `[].prefixes` | string\[\] | Families referenced by a prefix plus a key |
| `[].rowSources` | string\[\] | Row sources a bound table may name |
| `[].contractVersion` | number | Data contract version the server implements |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## List starters

GET `/templates/starters`

The FIZ editor's starters. Use them as complete examples when writing a template.

Authentication: an API key (`x-api-key`) or an OAuth access token.

**curl**

```shell
curl 'https://api.fiz.co/templates/starters' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.starters();
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.starters()
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->starters();
```

### Response `200`

Starters

| Field | Type | Description |
| --- | --- | --- |
| `[].id` | string | Starter identifier |
| `[].format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `[].language` | string | Template language — One of: `en`, `pt` |
| `[].fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `[].kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Get starter

GET `/templates/starters/{starterId}`

A starter with its data. Import it with POST /templates giving the same starterId.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `starterId` **required** | path | string | Starter identifier |

**curl**

```shell
curl 'https://api.fiz.co/templates/starters/STARTERID' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.starter('STARTERID');
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.starter("STARTERID")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->starter('STARTERID');
```

### Response `200`

Starter

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Starter identifier |
| `format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `language` | string | Template language — One of: `en`, `pt` |
| `fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `data` | object | The starter (pdfme JSON with FIZ fields), a complete and valid example |

### Errors

-   `400` Unknown starter
-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Validate template

POST `/templates/validate`

Checks a template as an import would, without storing it. A refusal comes back as a problem in the response, not as an error.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Request body

| Field | Type | Description |
| --- | --- | --- |
| `data` **required** | object | The template (pdfme JSON with FIZ fields) |
| `starterId` | string | Starter; sets the kind, the paper and whether the template is fiscal |
| `contractVersion` | number | Data contract version the template was made for |

**curl**

```shell
curl --request POST 'https://api.fiz.co/templates/validate' \
  --header "x-api-key: $FIZ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "data": {
    "basePdf": {
      "width": 210,
      "height": 297,
      "padding": [
        12,
        12,
        12,
        12
      ]
    },
    "schemas": [
      [
        {
          "name": "invoice",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "number"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "customer",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "profile",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "number",
          "type": "text",
          "readOnly": true,
          "content": "{invoice.type} {invoice.number}",
          "position": {
            "x": 12,
            "y": 60
          },
          "width": 186,
          "height": 12,
          "fontName": "Roboto Bold",
          "fontSize": 24
        },
        {
          "name": "items",
          "type": "table",
          "rowSource": "items",
          "columns": [
            "{item.nameWithDescription}",
            "{item.quantity}",
            "{item.unitPrice}",
            "{item.taxRate}",
            "{item.lineTotal}"
          ],
          "head": [
            "Descrição",
            "Qtd.",
            "Preço",
            "IVA",
            "Total"
          ],
          "headWidthPercentages": [
            46,
            10,
            16,
            10,
            18
          ],
          "showHead": true,
          "tableStyles": {
            "borderWidth": 0,
            "borderColor": "#000000"
          },
          "headStyles": {
            "fontName": "Roboto Bold",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "top",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 5,
              "right": 0,
              "bottom": 5,
              "left": 1
            }
          },
          "bodyStyles": {
            "fontName": "Roboto",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "middle",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "alternateBackgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 3,
              "right": 0,
              "bottom": 2,
              "left": 1
            }
          },
          "columnStyles": {
            "alignment": {
              "0": "left",
              "1": "left",
              "2": "right",
              "3": "right",
              "4": "right"
            }
          },
          "position": {
            "x": 12,
            "y": 85
          },
          "width": 186,
          "height": 40
        }
      ]
    ]
  },
  "contractVersion": 2
}'
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.validate({
  data: {
    basePdf: {
      width: 210,
      height: 297,
      padding: [
        12,
        12,
        12,
        12,
      ],
    },
    schemas: [
      [
        {
          name: 'invoice',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'number',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'customer',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'profile',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'number',
          type: 'text',
          readOnly: true,
          content: '{invoice.type} {invoice.number}',
          position: {
            x: 12,
            y: 60,
          },
          width: 186,
          height: 12,
          fontName: 'Roboto Bold',
          fontSize: 24,
        },
        {
          name: 'items',
          type: 'table',
          rowSource: 'items',
          columns: [
            '{item.nameWithDescription}',
            '{item.quantity}',
            '{item.unitPrice}',
            '{item.taxRate}',
            '{item.lineTotal}',
          ],
          head: [
            'Descrição',
            'Qtd.',
            'Preço',
            'IVA',
            'Total',
          ],
          headWidthPercentages: [
            46,
            10,
            16,
            10,
            18,
          ],
          showHead: true,
          tableStyles: {
            borderWidth: 0,
            borderColor: '#000000',
          },
          headStyles: {
            fontName: 'Roboto Bold',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'top',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 5,
              right: 0,
              bottom: 5,
              left: 1,
            },
          },
          bodyStyles: {
            fontName: 'Roboto',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'middle',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            alternateBackgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 3,
              right: 0,
              bottom: 2,
              left: 1,
            },
          },
          columnStyles: {
            alignment: {
              '0': 'left',
              '1': 'left',
              '2': 'right',
              '3': 'right',
              '4': 'right',
            },
          },
          position: {
            x: 12,
            y: 85,
          },
          width: 186,
          height: 40,
        },
      ],
    ],
  },
  contractVersion: 2,
});
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.validate({
    "data": {
        "basePdf": {
            "width": 210,
            "height": 297,
            "padding": [
                12,
                12,
                12,
                12,
            ],
        },
        "schemas": [
            [
                {
                    "name": "invoice",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "number",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "customer",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "profile",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "number",
                    "type": "text",
                    "readOnly": True,
                    "content": "{invoice.type} {invoice.number}",
                    "position": {
                        "x": 12,
                        "y": 60,
                    },
                    "width": 186,
                    "height": 12,
                    "fontName": "Roboto Bold",
                    "fontSize": 24,
                },
                {
                    "name": "items",
                    "type": "table",
                    "rowSource": "items",
                    "columns": [
                        "{item.nameWithDescription}",
                        "{item.quantity}",
                        "{item.unitPrice}",
                        "{item.taxRate}",
                        "{item.lineTotal}",
                    ],
                    "head": [
                        "Descrição",
                        "Qtd.",
                        "Preço",
                        "IVA",
                        "Total",
                    ],
                    "headWidthPercentages": [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    "showHead": True,
                    "tableStyles": {
                        "borderWidth": 0,
                        "borderColor": "#000000",
                    },
                    "headStyles": {
                        "fontName": "Roboto Bold",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "top",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 5,
                            "right": 0,
                            "bottom": 5,
                            "left": 1,
                        },
                    },
                    "bodyStyles": {
                        "fontName": "Roboto",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "middle",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "alternateBackgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 3,
                            "right": 0,
                            "bottom": 2,
                            "left": 1,
                        },
                    },
                    "columnStyles": {
                        "alignment": {
                            "0": "left",
                            "1": "left",
                            "2": "right",
                            "3": "right",
                            "4": "right",
                        },
                    },
                    "position": {
                        "x": 12,
                        "y": 85,
                    },
                    "width": 186,
                    "height": 40,
                },
            ],
        ],
    },
    "contractVersion": 2,
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->validate([
    'data' => [
        'basePdf' => [
            'width' => 210,
            'height' => 297,
            'padding' => [
                12,
                12,
                12,
                12,
            ],
        ],
        'schemas' => [
            [
                [
                    'name' => 'invoice',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'number',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'customer',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'profile',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'number',
                    'type' => 'text',
                    'readOnly' => true,
                    'content' => '{invoice.type} {invoice.number}',
                    'position' => [
                        'x' => 12,
                        'y' => 60,
                    ],
                    'width' => 186,
                    'height' => 12,
                    'fontName' => 'Roboto Bold',
                    'fontSize' => 24,
                ],
                [
                    'name' => 'items',
                    'type' => 'table',
                    'rowSource' => 'items',
                    'columns' => [
                        '{item.nameWithDescription}',
                        '{item.quantity}',
                        '{item.unitPrice}',
                        '{item.taxRate}',
                        '{item.lineTotal}',
                    ],
                    'head' => [
                        'Descrição',
                        'Qtd.',
                        'Preço',
                        'IVA',
                        'Total',
                    ],
                    'headWidthPercentages' => [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    'showHead' => true,
                    'tableStyles' => [
                        'borderWidth' => 0,
                        'borderColor' => '#000000',
                    ],
                    'headStyles' => [
                        'fontName' => 'Roboto Bold',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'top',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 5,
                            'right' => 0,
                            'bottom' => 5,
                            'left' => 1,
                        ],
                    ],
                    'bodyStyles' => [
                        'fontName' => 'Roboto',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'middle',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'alternateBackgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 3,
                            'right' => 0,
                            'bottom' => 2,
                            'left' => 1,
                        ],
                    ],
                    'columnStyles' => [
                        'alignment' => [
                            '0' => 'left',
                            '1' => 'left',
                            '2' => 'right',
                            '3' => 'right',
                            '4' => 'right',
                        ],
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 85,
                    ],
                    'width' => 186,
                    'height' => 40,
                ],
            ],
        ],
    ],
    'contractVersion' => 2,
]);
```

### Response `200`

Validation result

| Field | Type | Description |
| --- | --- | --- |
| `valid` | boolean | true if an import would accept the template |
| `problems` | object\[\] | The first problem found; validation stops at it. Empty when valid. |
| `problems[].code` | string | The error code an import would answer with |
| `problems[].detail` | string | Technical description of the fault (the path, field or element at fault), for the template's developer |
| `problems[].requiredVersion` | number | For TEMPLATES\_EDITOR\_OUTDATED: the contract version the template needs |
| `fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `contractVersion` | number | Data contract version the template needs |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Preview template

POST `/templates/preview`

Renders an unsaved template with the same PDF engine as issued documents, on a sample document. Every page carries «DOCUMENTO DE TESTE — SEM VALIDADE FISCAL». Validated like an import: an invalid template is refused with 400. Invoice templates only. To see the template on a real document, install it and download that document's PDF with templateId.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Request body

| Field | Type | Description |
| --- | --- | --- |
| `data` **required** | object | The template (pdfme JSON with FIZ fields) |
| `starterId` | string | Starter; sets the kind, the paper and whether the template is fiscal |
| `contractVersion` | number | Data contract version the template was made for |
| `language` | string | Preview language. Defaults to pt. — One of: `en`, `pt` |
| `documentType` | string | Sample document type. Defaults to INVOICE. — One of: `INVOICE`, `INVOICE_RECEIPT`, `SIMPLIFIED_INVOICE` |

**curl**

```shell
curl --request POST 'https://api.fiz.co/templates/preview' \
  --header "x-api-key: $FIZ_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "data": {
    "basePdf": {
      "width": 210,
      "height": 297,
      "padding": [
        12,
        12,
        12,
        12
      ]
    },
    "schemas": [
      [
        {
          "name": "invoice",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "number"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "customer",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "profile",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "number",
          "type": "text",
          "readOnly": true,
          "content": "{invoice.type} {invoice.number}",
          "position": {
            "x": 12,
            "y": 60
          },
          "width": 186,
          "height": 12,
          "fontName": "Roboto Bold",
          "fontSize": 24
        },
        {
          "name": "items",
          "type": "table",
          "rowSource": "items",
          "columns": [
            "{item.nameWithDescription}",
            "{item.quantity}",
            "{item.unitPrice}",
            "{item.taxRate}",
            "{item.lineTotal}"
          ],
          "head": [
            "Descrição",
            "Qtd.",
            "Preço",
            "IVA",
            "Total"
          ],
          "headWidthPercentages": [
            46,
            10,
            16,
            10,
            18
          ],
          "showHead": true,
          "tableStyles": {
            "borderWidth": 0,
            "borderColor": "#000000"
          },
          "headStyles": {
            "fontName": "Roboto Bold",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "top",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 5,
              "right": 0,
              "bottom": 5,
              "left": 1
            }
          },
          "bodyStyles": {
            "fontName": "Roboto",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "middle",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "alternateBackgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 3,
              "right": 0,
              "bottom": 2,
              "left": 1
            }
          },
          "columnStyles": {
            "alignment": {
              "0": "left",
              "1": "left",
              "2": "right",
              "3": "right",
              "4": "right"
            }
          },
          "position": {
            "x": 12,
            "y": 85
          },
          "width": 186,
          "height": 40
        }
      ]
    ]
  },
  "contractVersion": 2
}'
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.preview({
  data: {
    basePdf: {
      width: 210,
      height: 297,
      padding: [
        12,
        12,
        12,
        12,
      ],
    },
    schemas: [
      [
        {
          name: 'invoice',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'number',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'customer',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'profile',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'number',
          type: 'text',
          readOnly: true,
          content: '{invoice.type} {invoice.number}',
          position: {
            x: 12,
            y: 60,
          },
          width: 186,
          height: 12,
          fontName: 'Roboto Bold',
          fontSize: 24,
        },
        {
          name: 'items',
          type: 'table',
          rowSource: 'items',
          columns: [
            '{item.nameWithDescription}',
            '{item.quantity}',
            '{item.unitPrice}',
            '{item.taxRate}',
            '{item.lineTotal}',
          ],
          head: [
            'Descrição',
            'Qtd.',
            'Preço',
            'IVA',
            'Total',
          ],
          headWidthPercentages: [
            46,
            10,
            16,
            10,
            18,
          ],
          showHead: true,
          tableStyles: {
            borderWidth: 0,
            borderColor: '#000000',
          },
          headStyles: {
            fontName: 'Roboto Bold',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'top',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 5,
              right: 0,
              bottom: 5,
              left: 1,
            },
          },
          bodyStyles: {
            fontName: 'Roboto',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'middle',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            alternateBackgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 3,
              right: 0,
              bottom: 2,
              left: 1,
            },
          },
          columnStyles: {
            alignment: {
              '0': 'left',
              '1': 'left',
              '2': 'right',
              '3': 'right',
              '4': 'right',
            },
          },
          position: {
            x: 12,
            y: 85,
          },
          width: 186,
          height: 40,
        },
      ],
    ],
  },
  contractVersion: 2,
});
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.preview({
    "data": {
        "basePdf": {
            "width": 210,
            "height": 297,
            "padding": [
                12,
                12,
                12,
                12,
            ],
        },
        "schemas": [
            [
                {
                    "name": "invoice",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "number",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "customer",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "profile",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "number",
                    "type": "text",
                    "readOnly": True,
                    "content": "{invoice.type} {invoice.number}",
                    "position": {
                        "x": 12,
                        "y": 60,
                    },
                    "width": 186,
                    "height": 12,
                    "fontName": "Roboto Bold",
                    "fontSize": 24,
                },
                {
                    "name": "items",
                    "type": "table",
                    "rowSource": "items",
                    "columns": [
                        "{item.nameWithDescription}",
                        "{item.quantity}",
                        "{item.unitPrice}",
                        "{item.taxRate}",
                        "{item.lineTotal}",
                    ],
                    "head": [
                        "Descrição",
                        "Qtd.",
                        "Preço",
                        "IVA",
                        "Total",
                    ],
                    "headWidthPercentages": [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    "showHead": True,
                    "tableStyles": {
                        "borderWidth": 0,
                        "borderColor": "#000000",
                    },
                    "headStyles": {
                        "fontName": "Roboto Bold",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "top",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 5,
                            "right": 0,
                            "bottom": 5,
                            "left": 1,
                        },
                    },
                    "bodyStyles": {
                        "fontName": "Roboto",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "middle",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "alternateBackgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 3,
                            "right": 0,
                            "bottom": 2,
                            "left": 1,
                        },
                    },
                    "columnStyles": {
                        "alignment": {
                            "0": "left",
                            "1": "left",
                            "2": "right",
                            "3": "right",
                            "4": "right",
                        },
                    },
                    "position": {
                        "x": 12,
                        "y": 85,
                    },
                    "width": 186,
                    "height": 40,
                },
            ],
        ],
    },
    "contractVersion": 2,
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->preview([
    'data' => [
        'basePdf' => [
            'width' => 210,
            'height' => 297,
            'padding' => [
                12,
                12,
                12,
                12,
            ],
        ],
        'schemas' => [
            [
                [
                    'name' => 'invoice',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'number',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'customer',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'profile',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'number',
                    'type' => 'text',
                    'readOnly' => true,
                    'content' => '{invoice.type} {invoice.number}',
                    'position' => [
                        'x' => 12,
                        'y' => 60,
                    ],
                    'width' => 186,
                    'height' => 12,
                    'fontName' => 'Roboto Bold',
                    'fontSize' => 24,
                ],
                [
                    'name' => 'items',
                    'type' => 'table',
                    'rowSource' => 'items',
                    'columns' => [
                        '{item.nameWithDescription}',
                        '{item.quantity}',
                        '{item.unitPrice}',
                        '{item.taxRate}',
                        '{item.lineTotal}',
                    ],
                    'head' => [
                        'Descrição',
                        'Qtd.',
                        'Preço',
                        'IVA',
                        'Total',
                    ],
                    'headWidthPercentages' => [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    'showHead' => true,
                    'tableStyles' => [
                        'borderWidth' => 0,
                        'borderColor' => '#000000',
                    ],
                    'headStyles' => [
                        'fontName' => 'Roboto Bold',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'top',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 5,
                            'right' => 0,
                            'bottom' => 5,
                            'left' => 1,
                        ],
                    ],
                    'bodyStyles' => [
                        'fontName' => 'Roboto',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'middle',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'alternateBackgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 3,
                            'right' => 0,
                            'bottom' => 2,
                            'left' => 1,
                        ],
                    ],
                    'columnStyles' => [
                        'alignment' => [
                            '0' => 'left',
                            '1' => 'left',
                            '2' => 'right',
                            '3' => 'right',
                            '4' => 'right',
                        ],
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 85,
                    ],
                    'width' => 186,
                    'height' => 40,
                ],
            ],
        ],
    ],
    'contractVersion' => 2,
]);
```

### Response `200`

Preview PDF

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | File identifier |
| `name` | string | File name |
| `url` | string | Temporary URL of the preview PDF |

### Errors

-   `400` Invalid template or unsupported document type
-   `401` Unauthorized - API key missing or invalid
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Export template

GET `/templates/{id}`

Returns the full template, including data. The response can be sent as is to POST /templates in another company or the sandbox: the server-owned fields are ignored.

Authentication: an API key (`x-api-key`) or an OAuth access token.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` **required** | path | string | Unique template identifier |

**curl**

```shell
curl 'https://api.fiz.co/templates/ID' \
  --header "x-api-key: $FIZ_API_KEY"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.retrieve('ID');
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.retrieve("ID")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->retrieve('ID');
```

### Response `200`

Template

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique template identifier |
| `name` | string | Template name |
| `cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `language` | string | Template language — One of: `en`, `pt` |
| `kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `starterId` | string | Editor starter this template was created from. Send it back when importing: it sets the template's kind, paper and whether it is fiscal. |
| `contractVersion` | number | Data contract version the template needs. Send it back when importing. |
| `documentTypes` | string\[\] | Document types the template prints |
| `data` | object | The template designed in the FIZ template editor (pdfme JSON with FIZ fields) |
| `updatedAt` | string | Last change |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `403` The template belongs to the account or to another application
-   `404` Template not found
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Replace template

PUT `/templates/{id}`

Replaces a template's name, data, CAE and language. The kind, paper and fiscal character do not change.

Authentication: an API key (`x-api-key`) or an OAuth access token. Send an `Idempotency-Key` to retry this call safely.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` **required** | path | string | Unique template identifier |

### Request body

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `kind` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `format` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `fiscal` | boolean | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `documentTypes` | string\[\] | On import of a template without starterId: if it includes CREDIT\_NOTE or DEBIT\_NOTE, asks that the template print credit and debit notes. Granted only if the template prints the reference to the rectified document. Ignored with starterId and on replace. |
| `updatedAt` | string | Ignored on import: set by the server. Accepted so the response of GET /templates/{id} can be sent as is. |
| `name` **required** | string | Template name, unique among the templates of the same owner |
| `data` **required** | object | The template (the data field of GET /templates/{id}, or written from the published description). Validated on the server; an unknown field or a missing fiscal rule is refused with 400. |
| `contractVersion` **required** | number | Data contract version the template was made for (contractVersion from the export). A template that needs a higher version than the one given is refused. |
| `cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `language` | string | Template language. Defaults to pt. — One of: `en`, `pt` |
| `starterId` | string | Ignored on replace: a template's origin does not change. Accepted so an export can be sent as is. |

**curl**

```shell
# Once per operation. Keep it and reuse it on every retry.
IDEMPOTENCY_KEY=$(uuidgen)
```

```shell
curl --request PUT 'https://api.fiz.co/templates/ID' \
  --header "x-api-key: $FIZ_API_KEY" \
  --header 'Content-Type: application/json' \
  --header "Idempotency-Key: ${IDEMPOTENCY_KEY:?set the operation key first, in the step above}" \
  --data '{
  "name": "Modelo Ginásio",
  "data": {
    "basePdf": {
      "width": 210,
      "height": 297,
      "padding": [
        12,
        12,
        12,
        12
      ]
    },
    "schemas": [
      [
        {
          "name": "invoice",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "number"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "customer",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "profile",
          "type": "multiVariableText",
          "content": "{}",
          "text": "",
          "variables": [
            "name"
          ],
          "position": {
            "x": 12,
            "y": 12
          },
          "width": 4,
          "height": 4
        },
        {
          "name": "number",
          "type": "text",
          "readOnly": true,
          "content": "{invoice.type} {invoice.number}",
          "position": {
            "x": 12,
            "y": 60
          },
          "width": 186,
          "height": 12,
          "fontName": "Roboto Bold",
          "fontSize": 24
        },
        {
          "name": "items",
          "type": "table",
          "rowSource": "items",
          "columns": [
            "{item.nameWithDescription}",
            "{item.quantity}",
            "{item.unitPrice}",
            "{item.taxRate}",
            "{item.lineTotal}"
          ],
          "head": [
            "Descrição",
            "Qtd.",
            "Preço",
            "IVA",
            "Total"
          ],
          "headWidthPercentages": [
            46,
            10,
            16,
            10,
            18
          ],
          "showHead": true,
          "tableStyles": {
            "borderWidth": 0,
            "borderColor": "#000000"
          },
          "headStyles": {
            "fontName": "Roboto Bold",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "top",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 5,
              "right": 0,
              "bottom": 5,
              "left": 1
            }
          },
          "bodyStyles": {
            "fontName": "Roboto",
            "fontSize": 10,
            "characterSpacing": 0,
            "alignment": "left",
            "verticalAlignment": "middle",
            "lineHeight": 1,
            "fontColor": "#000000",
            "borderColor": "#000000",
            "backgroundColor": "",
            "alternateBackgroundColor": "",
            "borderWidth": {
              "top": 0,
              "right": 0,
              "bottom": 0,
              "left": 0
            },
            "padding": {
              "top": 3,
              "right": 0,
              "bottom": 2,
              "left": 1
            }
          },
          "columnStyles": {
            "alignment": {
              "0": "left",
              "1": "left",
              "2": "right",
              "3": "right",
              "4": "right"
            }
          },
          "position": {
            "x": 12,
            "y": 85
          },
          "width": 186,
          "height": 40
        }
      ]
    ]
  },
  "contractVersion": 2
}'
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.update('ID', {
  name: 'Modelo Ginásio',
  data: {
    basePdf: {
      width: 210,
      height: 297,
      padding: [
        12,
        12,
        12,
        12,
      ],
    },
    schemas: [
      [
        {
          name: 'invoice',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'number',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'customer',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'profile',
          type: 'multiVariableText',
          content: '{}',
          text: '',
          variables: [
            'name',
          ],
          position: {
            x: 12,
            y: 12,
          },
          width: 4,
          height: 4,
        },
        {
          name: 'number',
          type: 'text',
          readOnly: true,
          content: '{invoice.type} {invoice.number}',
          position: {
            x: 12,
            y: 60,
          },
          width: 186,
          height: 12,
          fontName: 'Roboto Bold',
          fontSize: 24,
        },
        {
          name: 'items',
          type: 'table',
          rowSource: 'items',
          columns: [
            '{item.nameWithDescription}',
            '{item.quantity}',
            '{item.unitPrice}',
            '{item.taxRate}',
            '{item.lineTotal}',
          ],
          head: [
            'Descrição',
            'Qtd.',
            'Preço',
            'IVA',
            'Total',
          ],
          headWidthPercentages: [
            46,
            10,
            16,
            10,
            18,
          ],
          showHead: true,
          tableStyles: {
            borderWidth: 0,
            borderColor: '#000000',
          },
          headStyles: {
            fontName: 'Roboto Bold',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'top',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 5,
              right: 0,
              bottom: 5,
              left: 1,
            },
          },
          bodyStyles: {
            fontName: 'Roboto',
            fontSize: 10,
            characterSpacing: 0,
            alignment: 'left',
            verticalAlignment: 'middle',
            lineHeight: 1,
            fontColor: '#000000',
            borderColor: '#000000',
            backgroundColor: '',
            alternateBackgroundColor: '',
            borderWidth: {
              top: 0,
              right: 0,
              bottom: 0,
              left: 0,
            },
            padding: {
              top: 3,
              right: 0,
              bottom: 2,
              left: 1,
            },
          },
          columnStyles: {
            alignment: {
              '0': 'left',
              '1': 'left',
              '2': 'right',
              '3': 'right',
              '4': 'right',
            },
          },
          position: {
            x: 12,
            y: 85,
          },
          width: 186,
          height: 40,
        },
      ],
    ],
  },
  contractVersion: 2,
});
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.update("ID", {
    "name": "Modelo Ginásio",
    "data": {
        "basePdf": {
            "width": 210,
            "height": 297,
            "padding": [
                12,
                12,
                12,
                12,
            ],
        },
        "schemas": [
            [
                {
                    "name": "invoice",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "number",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "customer",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "profile",
                    "type": "multiVariableText",
                    "content": "{}",
                    "text": "",
                    "variables": [
                        "name",
                    ],
                    "position": {
                        "x": 12,
                        "y": 12,
                    },
                    "width": 4,
                    "height": 4,
                },
                {
                    "name": "number",
                    "type": "text",
                    "readOnly": True,
                    "content": "{invoice.type} {invoice.number}",
                    "position": {
                        "x": 12,
                        "y": 60,
                    },
                    "width": 186,
                    "height": 12,
                    "fontName": "Roboto Bold",
                    "fontSize": 24,
                },
                {
                    "name": "items",
                    "type": "table",
                    "rowSource": "items",
                    "columns": [
                        "{item.nameWithDescription}",
                        "{item.quantity}",
                        "{item.unitPrice}",
                        "{item.taxRate}",
                        "{item.lineTotal}",
                    ],
                    "head": [
                        "Descrição",
                        "Qtd.",
                        "Preço",
                        "IVA",
                        "Total",
                    ],
                    "headWidthPercentages": [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    "showHead": True,
                    "tableStyles": {
                        "borderWidth": 0,
                        "borderColor": "#000000",
                    },
                    "headStyles": {
                        "fontName": "Roboto Bold",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "top",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 5,
                            "right": 0,
                            "bottom": 5,
                            "left": 1,
                        },
                    },
                    "bodyStyles": {
                        "fontName": "Roboto",
                        "fontSize": 10,
                        "characterSpacing": 0,
                        "alignment": "left",
                        "verticalAlignment": "middle",
                        "lineHeight": 1,
                        "fontColor": "#000000",
                        "borderColor": "#000000",
                        "backgroundColor": "",
                        "alternateBackgroundColor": "",
                        "borderWidth": {
                            "top": 0,
                            "right": 0,
                            "bottom": 0,
                            "left": 0,
                        },
                        "padding": {
                            "top": 3,
                            "right": 0,
                            "bottom": 2,
                            "left": 1,
                        },
                    },
                    "columnStyles": {
                        "alignment": {
                            "0": "left",
                            "1": "left",
                            "2": "right",
                            "3": "right",
                            "4": "right",
                        },
                    },
                    "position": {
                        "x": 12,
                        "y": 85,
                    },
                    "width": 186,
                    "height": 40,
                },
            ],
        ],
    },
    "contractVersion": 2,
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->update('ID', [
    'name' => 'Modelo Ginásio',
    'data' => [
        'basePdf' => [
            'width' => 210,
            'height' => 297,
            'padding' => [
                12,
                12,
                12,
                12,
            ],
        ],
        'schemas' => [
            [
                [
                    'name' => 'invoice',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'number',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'customer',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'profile',
                    'type' => 'multiVariableText',
                    'content' => '{}',
                    'text' => '',
                    'variables' => [
                        'name',
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 12,
                    ],
                    'width' => 4,
                    'height' => 4,
                ],
                [
                    'name' => 'number',
                    'type' => 'text',
                    'readOnly' => true,
                    'content' => '{invoice.type} {invoice.number}',
                    'position' => [
                        'x' => 12,
                        'y' => 60,
                    ],
                    'width' => 186,
                    'height' => 12,
                    'fontName' => 'Roboto Bold',
                    'fontSize' => 24,
                ],
                [
                    'name' => 'items',
                    'type' => 'table',
                    'rowSource' => 'items',
                    'columns' => [
                        '{item.nameWithDescription}',
                        '{item.quantity}',
                        '{item.unitPrice}',
                        '{item.taxRate}',
                        '{item.lineTotal}',
                    ],
                    'head' => [
                        'Descrição',
                        'Qtd.',
                        'Preço',
                        'IVA',
                        'Total',
                    ],
                    'headWidthPercentages' => [
                        46,
                        10,
                        16,
                        10,
                        18,
                    ],
                    'showHead' => true,
                    'tableStyles' => [
                        'borderWidth' => 0,
                        'borderColor' => '#000000',
                    ],
                    'headStyles' => [
                        'fontName' => 'Roboto Bold',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'top',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 5,
                            'right' => 0,
                            'bottom' => 5,
                            'left' => 1,
                        ],
                    ],
                    'bodyStyles' => [
                        'fontName' => 'Roboto',
                        'fontSize' => 10,
                        'characterSpacing' => 0,
                        'alignment' => 'left',
                        'verticalAlignment' => 'middle',
                        'lineHeight' => 1,
                        'fontColor' => '#000000',
                        'borderColor' => '#000000',
                        'backgroundColor' => '',
                        'alternateBackgroundColor' => '',
                        'borderWidth' => [
                            'top' => 0,
                            'right' => 0,
                            'bottom' => 0,
                            'left' => 0,
                        ],
                        'padding' => [
                            'top' => 3,
                            'right' => 0,
                            'bottom' => 2,
                            'left' => 1,
                        ],
                    ],
                    'columnStyles' => [
                        'alignment' => [
                            '0' => 'left',
                            '1' => 'left',
                            '2' => 'right',
                            '3' => 'right',
                            '4' => 'right',
                        ],
                    ],
                    'position' => [
                        'x' => 12,
                        'y' => 85,
                    ],
                    'width' => 186,
                    'height' => 40,
                ],
            ],
        ],
    ],
    'contractVersion' => 2,
]);
```

### Response `200`

Template updated

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique template identifier |
| `name` | string | Template name |
| `cae` | string\[\] | CAE codes the template applies to in the account's automatic choice |
| `language` | string | Template language — One of: `en`, `pt` |
| `kind` | string | What the template prints: invoices and related documents, or transport documents — One of: `INVOICE`, `TRANSPORT_DOCUMENT` |
| `format` | string | Paper the template is laid out for — One of: `A4`, `RECEIPT`, `RECEIPT_58` |
| `fiscal` | boolean | true if the template prints the fiscal document itself; false for an auxiliary print without fiscal value |
| `starterId` | string | Editor starter this template was created from. Send it back when importing: it sets the template's kind, paper and whether it is fiscal. |
| `contractVersion` | number | Data contract version the template needs. Send it back when importing. |
| `documentTypes` | string\[\] | Document types the template prints |
| `data` | object | The template designed in the FIZ template editor (pdfme JSON with FIZ fields) |
| `updatedAt` | string | Last change |

### Errors

-   `400` Invalid template: unknown field, missing fiscal rule, insufficient contract version or template limit reached
-   `401` Unauthorized - API key missing or invalid
-   `403` The template belongs to the account or to another application
-   `404` Template not found
-   `409` A request with this idempotency key is still being processed, or the outcome of the first attempt is unknown
-   `422` The idempotency key was already used with a different request body
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Delete template

DELETE `/templates/{id}`

Deletes a template.

Authentication: an API key (`x-api-key`) or an OAuth access token. Send an `Idempotency-Key` to retry this call safely.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `id` **required** | path | string | Unique template identifier |

**curl**

```shell
# Once per operation. Keep it and reuse it on every retry.
IDEMPOTENCY_KEY=$(uuidgen)
```

```shell
curl --request DELETE 'https://api.fiz.co/templates/ID' \
  --header "x-api-key: $FIZ_API_KEY" \
  --header "Idempotency-Key: ${IDEMPOTENCY_KEY:?set the operation key first, in the step above}"
```

**TypeScript**

```ts
import { Fiz } from '@fiz-co/sdk';

const fiz = new Fiz(); // reads FIZ_API_KEY
const result = await fiz.templates.delete('ID');
```

**Python**

```python
from fiz_sdk import Fiz

fiz = Fiz()  # reads FIZ_API_KEY
result = fiz.templates.delete("ID")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

$fiz = new Fiz\Fiz(); // reads FIZ_API_KEY
$result = $fiz->templates->delete('ID');
```

### Response `200`

Template deleted

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Identifier of the deleted template |
| `deleted` | boolean | true when the template was deleted |

### Errors

-   `401` Unauthorized - API key missing or invalid
-   `403` The template belongs to the account or to another application
-   `404` Template not found
-   `409` A request with this idempotency key is still being processed, or the outcome of the first attempt is unknown
-   `422` The idempotency key was already used with a different request body
-   `429` The OAuth connection’s request limit is reached. Nothing was executed: repeat the same request after Retry-After seconds.

## Errors

Errors share one shape: `statusCode`, `message`, `code` and `error`, with the request id in the `X-Request-Id` header.

## All resources

-   [Company](https://api.fiz.co/docs/api/company) ([Markdown](https://api.fiz.co/docs/api/company.md))
-   [Customers](https://api.fiz.co/docs/api/customers) ([Markdown](https://api.fiz.co/docs/api/customers.md))
-   [Items](https://api.fiz.co/docs/api/items) ([Markdown](https://api.fiz.co/docs/api/items.md))
-   [Invoices](https://api.fiz.co/docs/api/invoices) ([Markdown](https://api.fiz.co/docs/api/invoices.md))
-   [Recurring invoices](https://api.fiz.co/docs/api/recurring-invoices) ([Markdown](https://api.fiz.co/docs/api/recurring-invoices.md))
-   [Pro formas](https://api.fiz.co/docs/api/pro-formas) ([Markdown](https://api.fiz.co/docs/api/pro-formas.md))
-   [Transport documents](https://api.fiz.co/docs/api/transport-documents) ([Markdown](https://api.fiz.co/docs/api/transport-documents.md))
-   [Series](https://api.fiz.co/docs/api/series) ([Markdown](https://api.fiz.co/docs/api/series.md))
-   [PDF templates](https://api.fiz.co/docs/api/pdf-templates) ([Markdown](https://api.fiz.co/docs/api/pdf-templates.md))
-   [Exports](https://api.fiz.co/docs/api/exports) ([Markdown](https://api.fiz.co/docs/api/exports.md))
-   [Expenses](https://api.fiz.co/docs/api/expenses) ([Markdown](https://api.fiz.co/docs/api/expenses.md))
-   [VAT](https://api.fiz.co/docs/api/vat) ([Markdown](https://api.fiz.co/docs/api/vat.md))
-   [Bank](https://api.fiz.co/docs/api/bank) ([Markdown](https://api.fiz.co/docs/api/bank.md))
