> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a document template

> How to add a document template with REST.

<Tabs>
  <Tab title="RESTful REST API">
    ```javascript theme={null}
    var item = {}
    item.Name = "Created by unit test";
    item.Filename = "footemplate.txt";
    item.Tooltip = "Unit Tests FTW";
    item.SaveInDb = 1;
    item.LoadTemplateFromPlugin = 0;
    item = Post("api/v1/List/DocumentTemplate", item)
    ```

    At this point, the document template record has been created, but there is no content for the document template. We need to upload some document content to the new record:

    ```javascript theme={null}
    var id = item.DocumentTemplateId;
    content = "Hello {name}.";
    Put("api/v1/List/DocumentTemplate/" + id + "/content", content)
    ```
  </Tab>

  <Tab title="HTTP RPC Agent API">
    We could call `SaveDocumentTemplateEntity` and `SaveDocumentTemplateStream` separately as the REST API does, or we can use the agent call that does both in a single call:

    ```javascript theme={null}
    content = "Hello {name}.";

    var item = {}
    item.Name = "Created by unit test";
    item.Filename = "footemplate.txt";
    item.Tooltip = "Unit Tests FTW";
    item.SaveInDb = 1;
    item.LoadTemplateFromPlugin = 0;

    var req = { DocumentTemplateEntity: item, Stream: content }
    item = Post("api/v1/Agents/List/SetDocumentTemplateStream", req)
    ```

    At this point, the document template record has been created, and the content
    has been written to the archive.
  </Tab>
</Tabs>

<Note>
  The examples are given in JavaScripty pseudocode.
</Note>


## Related topics

- [Link a document template](/en/document/templates/admin/link-template.md)
- [Add items to the Privacy - Source list](/en/security/privacy/admin/add-source.md)
- [Document templates](/en/document/templates/learn/index.md)
- [Create a template document](/en/document/templates/learn/create.md)
- [Add email template](/en/email/admin/add-email-template.md)
