Skip to main content

The Box Doc Gen API Tutorial


Scott Picanco Box
Forum|alt.badge.img
The Box Doc Gen API

We are incredibly excited to announce the Box Doc Gen API, now available with Enterprise Advanced plan!

The Doc Gen API enables customers to dynamically generate custom documents in custom and third party applications, eliminating the tedious, time-consuming, and error-prone process of manually creating and modifying mission-critical documents while significantly improving operational efficiency. 

The Doc Gen API empowers teams to automatically generate custom, error-free documents in a matter of seconds — reducing turnaround times, mitigating risk, and eliminating manual data entry. With just a few clicks, your teams can leverage data from any data source, and instantly generate accurate, custom documents based on dynamic templates that handle everything from conditional formatting and dynamic tables to custom images and arithmetic calculations.

With the Box Doc Gen API, customers can:

Check out the Box Doc Gen tutorial from Alex Novotny below. If you want to learn more about the Box Doc Gen API, check out Rui Barbosa’s Box Doc Gen API Workshop.

 

Tutorial

Below, you’ll find a tutorial on how to generate an NDA using the Box Doc Gen API. The steps are broken into three parts: creating the template, labeling the template, and generating a document. The examples shown are in cURL to be framework agnostic, but our latest Box SDK libraries are updated so you can use them if you wish.

 

Prerequisites

Before you can use Box Doc Gen via the API, you’ll need to complete the following actions.

  • Your Box instance must have a subscription plan that includes Box Doc Gen. Developer accounts do not include Box Doc Gen. Reach out to your Box sales representative for more information if you would like to try out these features.
  • To use Box Doc Gen, you must have access to Microsoft Word, as it is required for creating and authoring your document templates. Box Doc Gen is designed to facilitate the dynamic generation of business documents, but it is important to note that Box does not have control over users’ access to Microsoft Word. Users must ensure they have the necessary permissions and access to Microsoft Word to create and author document templates effectively.
  • Box Doc Gen must be enabled by an admin in the Admin Console. If you are your instance’s Box Admin, you will find the necessary information on how to turn on this setting in the Enterprise Settings: Content & Sharing Tab documentation.
Configuring the Box Doc Gen enablement settings within the Admin Console
  • The appropriate scope must be added to a Box custom application. You can use any type of application. Find out how to set an app up in our developer docs.
Manage the Box Doc Gen application setting in the Admin Console

Create template

To begin, we need to create a template that can be used to generate a NDA for a new client. You can download this document to jump-start creating the template, or you can create your own from scratch. This NDA example also contains Box Sign template tags, so a document can be sent for signature after creation.

While it’s not required to use Microsoft Word to create the template, it can make it significantly easier — thanks to the Box Doc Gen Template Creator add-in for Microsoft Word. No matter how the document is created, it will need to be saved as a DOCX file type in order to generate documents with Box Doc Gen.

After downloading the file linked above, open it Microsoft Word. If using the plugin, install the add-in using these instructions. After installing the plugin you can then use a JSON object to generate tags or manually create them.

Also, note that you can use Microsoft Word online if you don’t wish to work with the file locally.

For this walkthrough, you can use this JSON file for the NDA template we are creating.

Leverage the Box Doc Gen Template Creator add-in in Microsoft Word to create Box Doc Gen templates

Click start with your data, followed by uploading the JSON file you downloaded. It should look like the below screenshot:

JSON data uploaded into the Box Doc Gen Template Creator add-in

After clicking “Generate tags,” you will see fields that can be used in the document.

Doc Gen template fields are created from imported JSON data

Add fields by placing your cursor where you’d like a value to go. Then, click the field in the list. In the screenshot below, fields that have been added are highlighted.

Highlighted text represents Box Doc Gen template tags

In addition to the JSON data, you can also add conditional logic using IF statements. Let’s add an “if” so that Part 3 of the document will only show if the NDA signer is in California.

Box Doc Gen enabled users to leverage conditional logic
 

Save the document. Make sure its DOCX.

 

Mark template

Now, let’s upload the document to Box and mark it as a Box Doc Gen template. You can do this in a few ways.

You could simply upload the file to Box (wherever you’d like to store it). Then, in the options menu, select “Mark as Doc Gen Template.”

Option 1: Marking Word files as Box Doc Gen templates

Or, you could go into the Relay Doc Gen menu, and create/upload it there.

Option 2: Uploading the pre-created Box Doc Gen template Word file directly in Box Doc Gen, accessible via Box Relay​​​

Finally, you could also use the Box Platform API to mark a file in Box as a template.

curl -L 'https://api.box.com/2.0/docgen_templates' \
     -H 'box-version: 2025.0' \
     -H 'Authorization: Bearer <ACCESS_TOKEN>' \
     -H 'Content-Type: application/json' \
     -D '{
        "file": {
            "id": "12345678",
            "type": "file"
        }
}'

Regardless of how you designate your template, you should see the file appear afterwards in the Doc Gen tab of the Relay menu option.

The Box Doc Gen template as it appears within Box Doc Gen in Box Relay

It will also appear in results returned by the Box Platform API endpoint for listing out Box Doc Gen templates.

{
  "limit": 10,
  "next_marker": null,
  "prev_marker": null,
  "entries": [{
    "file": {
      "id": "1749734642013",
      "type": "file"
    },
    "file_name": "Increo NDA Doc Gen Template.docx"
  }]
}

 

Generate document

After the above steps have been completed, you can generate a document using the template. Run the following command. Make sure to update the access token, file ID and destination folder ID, respectively.

curl -L 'https://api.box.com/2.0/docgen_batches' \
     -H 'box-version: 2025.0' \
     -H 'Authorization: Bearer ACCESS_TOKEN' \
     -d '{
        "file": {
            "id": "FILE_ID",
            "type": "file"
        },
        "input_source": "api",
        "destination_folder": {
            "id": "FOLDER_ID",
            "type": "folder"
        },
        "output_type": "docx",
        "document_generation_data": [
          {
            "generated_file_name": "Box Doc Gen Increo NDA",
            "user_input": {
              "contract": {
                "date": "18-08-2023",
                "companyName": "ABC Finance",
                "clientName": "Bob Smith",
                "engagementType": "Sprint Support",
                "companyIndustry": "Finance",
                "customerAddress": {
                  "state": "CA"
                }
              }
            }
          }
        ]
     }'

When a request to generate a document is completed, a job is created. The response you receive from the Box Platform API should look like this:

{
  "id": "d770504e-18a2-487f-baf9-7e6ec7d260e6",
  "type": "docgen_batch"
}

While one-off tutorials like this will be quick, larger more scaled projects may take more time. Also, since you can generate several documents in one call, they are batched together. You can use the endpoints described on this page to learn more about using the API to monitor job completion.

In addition to using the API to monitor job/batch progress, you can see all requests for a particular template in the Doc Gen activity tab.

Monitoring Box Doc Gen activity in Box

You’ll also find direct links to the generated document.

The generated document

And, since this NDA template has Box Sign tags, you could send it directly for signature using the Box UI or the API!

 

Wrap up

With this latest release, you can speed up time-consuming processes with document creation across your organization.

Also, it’s worth noting that this tutorial only demonstrated Box Doc Gen as a standalone solution., but you can use document generation in tandem with other Box products too. For example, you can send documents for signature after you generate them.

We’ve released additional Doc Gen endpoints. Learn more from our API reference pages.

Resources

0 replies

Be the first to reply!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings