# Templates API

## Deprecation notice❗️

Below APIs are deprecated and new version of APIs are available at <https://dashboard.docupilot.app/api-docs/swagger-ui/>

## Get list of Templates

<mark style="color:blue;">`GET`</mark> `https://api.docupilot.app/api/v1/templates`

This endpoint allows you to get templates in home folder. You can add filter or folder query params for more desired results.

#### Query Parameters

| Name   | Type   | Description                              |
| ------ | ------ | ---------------------------------------- |
| folder | number | Folder ID                                |
| filter | string | Possible Values are **all** \| **trash** |

#### Headers

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| apikey | string | API Key     |

{% tabs %}
{% tab title="200 Cake successfully retrieved." %}

```javascript
{
  "status": "success",
  "data": [
    {
      "id": 1170,
      "title": "Google Forms Dynamic Image",
      "description": "Students Certificate",
      "folder": null,
      "type": "docx",
      "document_status": "test",
      "created_time": "2018-11-07T17:26:10.375Z",
      "output_file_name": "Google Forms{{name}}",
      "output_type": "pdf",
      "timezone": "Pacific/Midway"
    },
    {
      "id": 1171,
      "title": "Zoho Forms",
      "description": "Students Certificate",
      "folder": null,
      "type": "pptx",
      "document_status": "test",
      "created_time": "2018-11-07T17:26:10.375Z",
      "output_file_name": "Google Forms{{name}}",
      "output_type": "pptx",
      "timezone": "Pacific/Midway"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Get a Template

<mark style="color:blue;">`GET`</mark> `https://api.docupilot.app/api/v1/templates/:id`

This endpoint allows you to get details of each template.

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | integer | Template ID |

#### Headers

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| apikey | string | API Key     |

{% tabs %}
{% tab title="200 " %}

```
{
  "status": "success",
  "data": {
    "id": 1170,
    "title": "Google Forms Dynamic Image",
    "description": "Students Certificate",
    "folder": null,
    "type": "docx",
    "document_status": "active",
    "created_time": "2018-11-07T17:26:10.375Z",
    "output_file_name": "certificate - {{name}}",
    "output_type": "pdf",
    "timezone": "Pacific/Midway"
  }
}
```

{% endtab %}
{% endtabs %}

## Create a new Template

<mark style="color:green;">`POST`</mark> `https://api.docupilot.app/api/v1/templates`

This endpoint allows you to create a new template.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| apikey       | string | API Key          |

#### Request Body

| Name               | Type   | Description                                                                                        |                       |                       |                       |                                                      |
| ------------------ | ------ | -------------------------------------------------------------------------------------------------- | --------------------- | --------------------- | --------------------- | ---------------------------------------------------- |
| output\_file\_name | string | <p>File name for the generated document. <br>Example : <strong>Certificate - {{name}}</strong></p> |                       |                       |                       |                                                      |
| folder             | string | Folder ID                                                                                          |                       |                       |                       |                                                      |
| document\_status   | string | Allowed values **test** \| **active.** Default : test                                              |                       |                       |                       |                                                      |
| description        | string | Description for the template                                                                       |                       |                       |                       |                                                      |
| type               | string | <p>Allowed values <strong>html</strong>                                                            | <strong>docx</strong> | <strong>pptx</strong> | <strong>xlsx</strong> | <strong>fillable\_pdf</strong><br>Default : html</p> |
| title              | string | Title for the template                                                                             |                       |                       |                       |                                                      |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Update a Template

<mark style="color:orange;">`PUT`</mark> `https://api.docupilot.app/api/v1/templates/:id`

This endpoint allows you to update a template&#x20;

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| apikey       | string | API Key          |
| Content-Type | string | application/json |

#### Request Body

| Name               | Type   | Description                                                                      |
| ------------------ | ------ | -------------------------------------------------------------------------------- |
| title              | string | Title for the template                                                           |
| description        | string | Description for the template                                                     |
| document\_status   | string | Allowed values test \| active                                                    |
| folder             | string | Folder ID                                                                        |
| output\_file\_name | string | <p>File name for the generated document.<br>Example : Certificate - {{name}}</p> |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Delete template

<mark style="color:red;">`DELETE`</mark> `https://api.docupilot.app/api/v1/templates/:id`

The template will be moved to Trash and will be deleted permanently after 30 days

#### Query Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String | Template ID |

#### Headers

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| apikey<mark style="color:red;">\*</mark> | String | API Key     |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

## Add / Update Template Content

<mark style="color:green;">`POST`</mark> `https://api.docupilot.app/api/v1/templates/:id/content`

This end point allows you to add or update template content.

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | string | Template ID |

#### Headers

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| apikey | string | API Key     |

#### Request Body

| Name | Type   | Description                          |
| ---- | ------ | ------------------------------------ |
| file | object | DOCX, PPTX, XlSX, Fillable\_PDF file |

{% tabs %}
{% tab title="200 " %}

```
{
  "status": "success",
  "data": null
}
```

{% endtab %}

{% tab title="400 " %}

```
{
  "status": "error",
  "data": "Invalid Helper used. Helper \"user\" does not exist\nDid you mean to write user_name"
}
```

{% endtab %}
{% endtabs %}

## Get Schema for a template

<mark style="color:blue;">`GET`</mark> `https://api.docupilot.app/api/v1/templates/:id/schema`

This endpoint allows you to get token details of the template.

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | integer | Template ID |

#### Headers

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| apikey | string | API Key     |

{% tabs %}
{% tab title="200 " %}

```
{
  "status": "success",
  "data": {
    "schema": [
      {
        "name": "invoice_number",
        "type": "string"
      },
      {
        "name": "client_name",
        "type": "string"
      },
      {
        "name": "client_address",
        "type": "string"
      },
      {
        "name": "client_state",
        "type": "string"
      },
      {
        "name": "client_country",
        "type": "string"
      },
      {
        "name": "client_zipcode",
        "type": "string"
      },
      {
        "name": "status",
        "type": "string"
      },
      {
        "name": "orders",
        "type": "array",
        "fields": [
          {
            "name": "item",
            "type": "string"
          },
          {
            "name": "price",
            "type": "string"
          },
          {
            "name": "quantity",
            "type": "string"
          },
          {
            "name": "total",
            "type": "string"
          }
        ],
        "generics": "object"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Merge a document

<mark style="color:green;">`POST`</mark> `https://api.docupilot.app/api/v1/templates/:id/merge`

This endpoint allows you to create a new document from a template.

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | string | Template ID |

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |
| apikey       | string | API Key          |

#### Request Body

| Name        | Type   | Description        |
| ----------- | ------ | ------------------ |
| user\_email | string | <John@example.com> |
| name        | string | John               |

{% tabs %}
{% tab title="200 " %}

```
{
  "status": "success",
  "data": {
    "file_url": "https://docupilot-documents.s3.amazonaws.com/temp/1/e419595c-d709-455b-9acd-1109eb09baec/certificate%20-%202019-04-05.docx?AWSAccessKeyId=AKIAJTKZBQI56EOPGLFQ&Signature=PRedVHdjK0oE0oEYH5hi%2B8Ein%2FY%3D&Expires=1554549057",
    "file_name": "certificate - 2019-04-05.docx"
  }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The body parameters for Merge API depends on the tokens configured in the document.
{% endhint %}
