> ## Documentation Index
> Fetch the complete documentation index at: https://superofficeas-bugfix-ty-screen-designer-paradox.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate a document

> How to generate a document with REST.

<Tabs>
  <Tab title="RESTful REST API">
    ```javascript theme={null}
    var doc = {}
    doc.Header = "Testing test";
    doc.Name = "foo.doc";
    doc.OurRef = "foo/1";
    doc.YourRef = "bar/99";
    doc.Description = "BAZ FTW";
    doc.DocumentTemplate = { DocumentTemplateId = 2 };
    doc.Contact = { ContactId = 25 };
    doc.Person = { PersonId = 63, ContactId = 25, };
    doc = Post("api/v1/Document", doc);
    ```

    At this point, the document record has been created, but the content is not generated yet. We can either upload some content directly:

    ```javascript theme={null}
    id = res.DocumentId;
    content = "This is some document content.";
    Put("api/v1/Document/" + id + "/content", content)
    ```

    Or we can use the document template to generate a fresh document for us:

    ```javascript theme={null}
    id = res.DocumentId;
    Post("api/v1/Document/" + id + "/content")
    content = Get("api/v1/Document/" + id + "/content")
    ```
  </Tab>

  <Tab title="HTTP RPC Agent API">
    ```javascript theme={null}
    var doc = {}
    doc.Header = "Testing test";
    doc.Name = "foo.doc";
    doc.OurRef = "foo/1";
    doc.YourRef = "bar/99";
    doc.Description = "BAZ FTW";
    doc.DocumentTemplate = { DocumentTemplateId = 2 };
    doc.Contact = { ContactId = 25 };
    doc.Person = { PersonId = 63, ContactId = 25 };
    doc = Post("api/v1/Agents/Document/SaveDocumentEntity", doc);
    ```

    At this point, the document record has been created, but the content is not generated yet. We can either upload some content directly:

    ```javascript theme={null}
    id = doc.DocumentId;
    content = "This is some document content.";
    var req = { DocumentId: id, Stream: content }
    doc = Post("api/v1/Agents/Document/SetDocumentStreamFromId", req);
    ```

    Or we can use the document template to generate a fresh document for us:

    ```javascript theme={null}
    id = doc.DocumentId;
    var req = { DocumentId: id }
    doc = Post("api/v1/Agents/Document/CreateNewPhysicalDocumentFromTemplate", req);
    ```
  </Tab>
</Tabs>

This will generate a new document based on the template and return the updated document object to us.

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