# Document

## Overview

A Document resources represents the template configuration for&#x20;

### Fields

<table><thead><tr><th width="224">Field</th><th width="139">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>String</td><td>The ID of the document.</td></tr><tr><td>documentType</td><td>String</td><td>The type of document for this template. This will either be the value <code>"GOOGLE_DOCS"</code> or <code>"GOOGLE_SLIDES"</code> depending on the file that is selected.</td></tr><tr><td>file</td><td><a href="google-file">Google File</a></td><td>The Google File that is a template document within the workflow. This file will be copied to create the output document.</td></tr><tr><td>outputName</td><td>String</td><td>A templated string used to generate the name for the output created from this template. </td></tr><tr><td>createPDFCopy</td><td>Boolean</td><td>A flag to enable creating a PDF copy of the output document.</td></tr><tr><td>removeOutput</td><td>Bolean</td><td>A flag to enable removing the original output document (Google Docs/Slides) files after a PDF copy has been made.</td></tr><tr><td>enablePdfPassword</td><td>Boolean</td><td>A flag to enable pdf encryption of the created PDF.</td></tr><tr><td>pdfPassword</td><td>String</td><td>A templated string used to generate the password for the PDF. Only used if the `enablePdfPassword` flag is enabled.</td></tr><tr><td>PdfPasswordPreventCopy</td><td>Boolean</td><td>A flag to prevent content of the PDF being copied when the PDF is protected with a password.</td></tr><tr><td>previewUrl</td><td>String</td><td>A url to the embedded editor used for non-Portant users changes to this document using source fields. It is assumed these users can access the associated Google File.<br><br><mark style="color:red;"><strong>NOTE: This feature has not yet been implemented and my be subject to change.</strong></mark></td></tr></tbody></table>

### Example

```
{
    "id": "doc_5LGGqC5S78RNS0",
    "documentType": "GOOGLE_DOCS",
    "file": {
        "id": "1uNfBHAKhcgRsiftb7xRpTJRS0k9LY1iX1gUnTOE0zU4",
        "name": "Complete Workflow Please - [Template]",
        "url": "https://docs.google.com/document/d/1uNfBHAKhcgRsiftb7xRpTJRS0k9LY1iX1gUnTOE0zU4/edit?usp=drivesdk",
        "mimeType": "application/vnd.google-apps.document"
    },
    "outputName": "Document for {{First Name}}",
    "createPdfCopy": true,
    "removeOutput": false,
    "enablePdfPassword": false,
    "pdfPassword": "Password-{{Secret Number}}",
    "pdfPasswordPreventCopy": false,
    "previewUrl": "https://preview.portant.co/doc_5LGGqC5S78RNS0"
}
```

## Endpoints

### List all Documents for a Workflow

```
GET /workflows/<wkf_id>/documents/
```

List all documents of the specific workflow as specified by the id.

#### Responses

| Status           | Body             |
| ---------------- | ---------------- |
| 200 OK           | Array\<Document> |
| 403 Unauthorised | Error            |

### Create a Document for a Workflow

```
POST /workflows/<wkf_id>/documents/
```

Create a new document for the specified workflow.

#### Request

A *create* Document object as JSON.

The payload may contain an optional `file_id` field with a file ID for a file in Google Drive that the requesting user has access to.

```
{
    file_id?: "1uNfBHAKhcgRsiftb7xRpTJRS0k9LY1iX1gUnTOE0zU4"
}
```

Alternatively, the `file_id` can be omitted in order to create a new document.

#### Responses

| Status           | Body     |
| ---------------- | -------- |
| 201 Created      | Document |
| 400 Bad Request  | Error    |
| 403 Unauthorised | Error    |

### Get a Document

```
GET /workflows/<wkf_id>/documents/<doc_id>/
```

Retrieve a specific document of a specific workflow.

#### Responses

| Status           | Body     |
| ---------------- | -------- |
| 200 OK           | Document |
| 403 Unauthorised | Error    |

### Update a Document

```
PATCH /workflows/<wkf_id>/documents/<doc_id>/
```

Update a specific document as specified by its id.

#### Request

A *partial* Document object as JSON.

The payload may contain an of the editable fields of the document. Note, the selected file for a document can not be changed once it is created.

```
{
    "outputName"?: "New outputName for {{First Name}}",
    "pdfPassword"?: "NewPassword-{{Secret Number}}",
    "enablePdfPassword"?: true,
    "enablePdfPreventCopy"?: true,
}
```

#### Responses

| Status           | Body     |
| ---------------- | -------- |
| 200 OK           | Document |
| 400 Bad Request  | Error    |
| 403 Unauthorised | Error    |
