Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.box.com/llms.txt

Use this file to discover all available pages before exploring further.

Note: Box Doc Gen template tags currently support English only. Test your templates to verify they meet your language requirements before production use.
Template tags let you create document templates that automatically fill in with data. When you generate a document, Box Doc Gen finds the tags in your template, matches them to fields in your JSON input, and replaces each tag with the corresponding value. Use template tags to dynamically generate:
  1. Text
  2. Images
  3. Tables
  4. Lists
  5. Conditions
  6. Calculations
  7. Box Sign template tags

1. Text tags

A text tag is any data field of type, string, number, or date. In the example below, you can turn id, date, customerId, customerName, currency, amount into text tags.
{
  "invoice":{
    "id": "Inv1203",
    "date": "13-03-2023",
    "customerId": "90158",
    "customerName": "Acme Inc",
    "currency": "$",
    "amount": 5060.50
  }
}
In the output document generated, all the template tags will be replaced with the input data.
Note: Box Doc Gen tags do not support spaces or hyphens between key words in the tag. For example, **{{first name}}** or **{{first-name}}** are not supported.
Document templateOutput document
Invoice
Invoice id: {{invoice.id}}
Invoice date: {{invoice.date}}
Customer details:
Customer id: {{invoice.customerId}}
Customer name: {{invoice.customerName}}
Amount Payable:
{{invoice.currency}}{{invoice.amount}}
Invoice
Invoice id: Inv1203
Invoice date: 13-03-2023
Customer details:
Customer id: 90158
Customer name: Acme Inc
Amount Payable:
$5060.50

Optional tags

Input formatInput dataOutput data
{{invoice.customerName}}-{{invoice.customerName}}
{{invoice.customerName :: optional}}-

Default values

Input formatInput dataOutput data
{{invoice.customerName}}-{{invoice.customerName}}
{{invoice.customerName :: default(“Box Inc”)}}-Box Inc

Formatting text tags

Input formatInput dataOutput dataSupported 
via script
Supported 
via Add-in
{{invoice.customerName :: uppercase}}Acme IncACME INCYesNo
{{invoice.customerName :: lowercase}}Acme Incacme incYesNo
{{invoice.date :: format(
“dd-mm-yyyy”) }}
13-03-202313-03-2023YesNo
{{invoice.date :: format(“mm-dd-yyyy”) }}13-03-202303-13-2023YesNo
{{invoice.date :: format(“dd-mmm-yy”) }}13-03-202313-Mar-22YesNo
{{invoice.id :: format(“xxx-xxxx”) }}Inv1203Inv-1203YesNo
{{invoice.amount :: format(“EU-Number”) }}300000300.000YesNo
{{invoice.amount :: format(“US-Number”) }}300000300,000YesNo

Rich text

Box Doc Gen allows you to generate documents with rich text. If the input JSON data contains HTML tags such as bold, italic, underline, line breaks, paragraphs, anchors, or images, Doc Gen automatically interprets them as rich text and applies the relevant formatting.
HTML TagsJSON dataOutput
Bold{ “company”: “<b>Acme Inc.</b> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<b> 999-999-9999</b>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Italic{ “company”: “<i>Acme Inc.</i> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<i> 999-999-9999</i>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Underline{ “company”: “<u>Acme Inc.</u> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<u> 999-999-9999</u>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Bold, Italic and Underline{ “company”: “<b><i><u>Acme Inc.</u></i></b>A fictional company that features prominently in the Road Runner show as a running gag. Phone:<b><i><u> 999-999-9999</u></i></b>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Strong{ “company”: “<strong>Acme Inc.</strong> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<strong> 999-999-9999</strong>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Span{ “company”: “<span>Acme Inc.</span> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<span> 999-999-9999</span>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Emphasized{ “company”: “<em>Acme Inc.</em> A fictional company that features prominently in the Road Runner show as a running gag. Phone:<em> 999-999-9999</em>” }Acme Inc. A fictional company that features prominently in the Road Runner show as a running gag. Phone: 999-999-9999
Line breaks{ “company”: “<b>Acme Inc.</b>  \n A fictional company that features prominently in the Road Runner show as a running gag. \n Phone:<b> 999-999-9999</b>” }Acme Inc.  
A fictional company that features prominently in the Road Runner show as a running gag. 
Phone: 999-999-9999
Paragraphs{ “company”: “<b>Acme Inc.</b>  <p> A fictional company that features prominently in the Road Runner show as a running gag. </p>  <p> Phone:<b> 999-999-9999</b>”</p> }Acme Inc. 
A fictional company that features prominently in the Road Runner show as a running gag. 
Phone: 999-999-9999
Ordered list<ol><li>Blue</li><li>Green</li><li>Red</li></ol>
  1. Blue
  2. Green
  3. Red
Unordered list<ul><li>Blue</li><li>Green</li><li>Red</li></ul>
  • Blue
  • Green
  • Red

2. Image tags

Doc Gen enables you to embed any image file in Box into the generated document. To do this, you will need to follow the following steps:

1. Upload the image file to Box

The image file being used for Document Generation has to be uploaded to Box. Generating documents via API If you are using a service account to generate the document via APIs, ensure the service account has access to the file.

2. Author the Doc Gen template

Doc Gen allows you to generate documents using images in the following ways
  • Generating documents from a placeholder image
  • Generating documents with HTML images
Generating documents from a placeholder image:
Authoring a Doc Gen template using Add-in for Microsoft Word To insert an Image tag using the add-in:
  1. In the Box Doc Gen Template Creator add-in, create an image tag using your desired placeholder image
  2. Navigate to the Document Tags > Image Tags.
  3. In the document, select the area to insert an Image tag.
  4. Double-click the image tag to insert it.
The result is a placeholder image, which can be dynamically replaced by the input data from the Box Doc Gen API, or any other upstream systems. Placeholder.png The dimensions, and alignments of the placeholder image can be altered using Microsoft Word functions. These properties are retained in the output document. The placeholder image has the following code added to the image under “Alt Text”. To view it: Select the image -> Right Click -> View Alt Text
{
  "image-path": "singleImage",
  "alt-text": ""
}
Note:
  • The image-path - is the key field for the Image from the JSON Payload used to make a request to Generate a document.
  • You can also add a placeholder image by simply dragging and dropping it into the document or inserting an image placeholder. However, make sure to manually include the required code in the ALT TEXT field.
Repeating images within a for-loop: To generate a document with multiple images in a for-loop, ensure the image is wrapped in a For function as below,
{{ for item in multipleImages }}

{
  "image-path": "{{ item.id }}",
  "alt-text": ""
}

{{ endfor }}
Repeating images within a table-loop: To generate a document with multiple images in a table-loop, ensure the image is wrapped in a Table function as below,
{{ tablerow item in multipleImages }}
{{ item.name }}Embedded image whose Alt Text includes JSON with image-path
{{ endtablerow }}
Note: Ensure to include the image path in the ALT TEXT section of the image
{
  "image-path": "singleImage",
  "alt-text": ""
}

Generating documents with HTML images:

To generate a document with a HTML image from the JSON payload, include a Text tag in the template.
For example: {{htmlImage}}
Note: This method only supports generation of simple images, and does not support generation of repeating images in For-loops and Table-loops.

3. Create the JSON Payload to Generate the document

Generating documents from a placeholder image:
To generate a document with an image file in Box, use the following schema:
  1. Key used in the Placeholder image (Ex: singleImage)
  2. id - to pass the file id of the Image file in Box
  3. type - to signify that this is an image file to be embedded in the document
{
  "singleImage": {
    "id": "1948600448426",
    "type": "image",
    "name": "Title for image 1"
  }
}
Note: The image file id mentioned here should refer to your file id in Box.
{
  "image-path": "singleImage",
  "alt-text": ""
}
Generating a document from a Placeholder with multiple images To generate a document with multiple image files in Box, run an array of image schema as shown below,
{
  "multipleImages": [
    {
      "id": "1948600448426",
      "type": "image",
      "name": "Title for image 2"
    },
    {
      "id": "1948600448427",
      "type": "image",
      "name": "Title for image 3"
    },
    {
      "id": "1948600448428",
      "type": "image",
      "name": "Title for image 4"
    }
  ]
}
Generating documents with HTML images:
To include an image from Box in your document using an HTML image tag, define the JSON schema in the following format:
{
  "htmlImage": "<img src='file://2097093405102' alt='here is a sample image' height='500' width='500'/>"
}
In this example:
  • file://2097093405102 refers to the file ID of the image stored in Box
  • height and width define the display size of the image
  • alt specifies the alternative text for the image

4. Make a Document Generation request

Doc Gen allows you to create documents with embedded images sourced directly from Box. You can include images in your generated documents using one of the following methods:
  • Box Doc Gen API – Generate documents with images programmatically. Refer to the Box Doc Gen API documentation for step-by-step guidance.
  • Box Doc Gen Web App – Create documents with embedded images through the web interface. See the documentation for detailed instructions.
Salesforce Integration – Generate documents with images by referencing a Box file ID. Ensure the required JSON schema pattern is followed. For setup and usage, refer to the Salesforce integration documentation.

3. Table tags

An array from the input data can be used to generate and dynamically format a table. In the following example:
  • items is an array that can be rendered as a dynamic table.
  • id, name, quantity, price, amount are the variables within the array that can be rendered as individual columns to the dynamic table.
{
  "invoice":{
    "number": "Inv1203",
    "date": "13-03-2023",
    "customerId": "90158",
    "currency": "$",
    "amount": 5060.50,
    "items": [
      {
        "id": 1,
        "name": "A4 Papers",
        "quantity": 100,
        "price": 29,
        "amount": 2900
      },
      {
        "id": 2,
        "name": "Ink  Cartridge",
        "quantity": 40,
        "price": 39,
        "amount": 1560
      },
      {
        "id": 3,
        "name": "Adhesive tape",
        "quantity": 20,
        "price": 30,
        "amount": 600.50
      }
    ]
  }
}

Document Template

The document template with inserted tags will look as follows:
IdNameQtyPrice
{{tablerow item in invoice.items}}
{{item.id}}{{item.name}}{{item.quantity}}{{item.price}}
{{endtablerow}}

Output

Box Doc Gen automatically identifies the table tags added to the document template, matches them with the fields in the input JSON data, and performs a few iterations to generate a complete table for the input data. The output table on the generated document will look as follows:
IdNameQtyPrice
1A4 Papers10029
2Ink Cartridge4039
3Adhesive tape2030

4. List tags

An array from the input data can be used to dynamically generate an ordered or unordered list. In the following example:
  • items is an array that can be rendered as a dynamic list.
  • id, name, quantity, price, amount are the variables within the array that can be rendered as a repetitive field in the list.
{
  "invoice":{
    "number": "Inv1203",
    "date": "13-03-2023",
    "customerId": "90158",
    "currency": "$",
    "amount": 5060.50,
    "items": [
      {
        "id": 1,
        "name": "A4 Papers",
        "quantity": 100,
        "price": 29,
        "amount": 2900
      },
      {
        "id": 2,
        "name": "Ink  cartridge",
        "quantity": 40,
        "price": 39,
        "amount": 1560
      },
      {
        "id": 3,
        "name": "Adhesive tape",
        "quantity": 20,
        "price": 30,
        "amount": 600.50
      }
    ]
  }
 }
The input data can be used to generate different types of lists:
Use caseDocument templateOutput document
Adding a bullet listList of products:

{{ for item in invoice.items }}

{{item.name}}
{{ endfor }}
List of products:

• A4 Papers
• Ink cartridge
• Adhesive tape
Adding a bullet list with one or more variablesList of products:

{{ for item in invoice.items }}

{{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

• A4 Papers, 100
• Ink cartridge, 40
• Adhesive tape, 20
Adding a squared bullet list with one or more variablesList of products:

{{ for item in invoice.items }}

{{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

• A4 Papers, 100
• Ink cartridge, 40
• Adhesive tape, 20
Adding a white bullet list with one or more variablesList of products:

{{ for item in invoice.items }}

{{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

• A4 Papers, 100
• Ink cartridge, 40
• Adhesive tape, 20
Adding a numbered list with one or more variablesList of products:

{{ for item in invoice.items }}

1. {{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

1. A4 Papers, 100
2. Ink cartridge, 40
3. Adhesive tape, 20
Adding a roman numbered list with one or more variablesList of products:

{{ for item in invoice.items }}

1. {{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

1. A4 Papers, 100
2. Ink cartridge, 40
3. Adhesive tape, 20
Adding an alphabetical list with one or more variablesList of products:

{{ for item in invoice.items }}

1. {{item.name}}, {{item.quantity}}
{{ endfor }}
List of products:

1. A4 Papers, 100
2. Ink cartridge, 40
3. Adhesive tape, 20

Formatting lists

Box Doc Gen templates support a wide range of custom codes that you can use in the document template. Taking the following JSON input data as an example, you can introduce different separators and delimiters.
{
  "items": ["A4 Papers", "Ink  cartridge", "Adhesive tape"]
}
Type of listDocument templateOutput document
List - with comma separator {{ items :: delimiter(“,”)}}A4 Papers, Ink cartridge, Adhesive tape
List - with semicolon separator {{ items :: delimiter(“;”)}}A4 Papers; Ink cartridge; and Adhesive tape
List - with customer separator{{ items :: delimiter(“~”)}}A4 Papers~ Ink cartridge~ Adhesive tape
List - with Comma and last delimiter{{ items :: delimiter(“,”) , lastdelimiter (“, and”)}}A4 Papers, Ink cartridge, and Adhesive tape
List - with semicolon and last delimiter{{ items :: delimiter(“;”) , lastdelimiter (“; and”)}}A4 Papers; Ink cartridge; and Adhesive tape
List - with custom separator and last delimiter{{ items | delimiter(“”) , lastdelimiter (“ and”)}}A4 Papers~ Ink cartridge~ and Adhesive tape

5. Conditions

You can use conditions to add input to the output document. The Box Doc Gen Template Creator add-in can help you define these conditions within the document template.

Supported conditions and operators

Tag typeConditions supportedOperators supported to chain conditions
String==(is equal to), !=(is not equal to), isPresentAND, OR
DateisPresentAND, OR
Number<, >, ==, !=, >=, <=AND, OR
The following JSON serves as input for defining conditions for the Box Doc Gen template.
{
  "invoice":{
    "number": "Inv1203",
    "date": "13-03-2023",
    "customerId": "90158",
    "currency": "$",
    "amount": 5060.50,
    "paymentMethod": "Cheque",
    "paymentTerms": "Net60",
    "deliveryDate": "23-03-2023",
    "items": [
      {
        "id": 1,
        "name": "A4 Papers",
        "quantity": 100,
        "price": 29,
        "amount": 2900
      },
      {
        "id": 2,
        "name": "Ink cartridge",
        "quantity": 40,
        "price": 39,
        "amount": 1560
      },
      {
        "id": 3,
        "name": "Adhesive tape",
        "quantity": 20,
        "price": 30,
        "amount": 600.50
      }
    ]
  }
 }
Use caseDocument templateOutput document
Introducing content based on payment method and payment termsPayment terms:

{{ if invoice.paymentMethod == “Online Transfer” AND invoice.paymentTerms == “Net30” }} 

• The invoice must be paid within 30 calendar days of the invoice date.
• The payment reference should contain the invoice number as reference.
{{ elseif invoice.paymentMethod == “Cheque” AND invoice.paymentTerms == “Net60” }} 

• The invoice must be paid within 60 calendar days of the invoice date.
• The payment reference should contain the invoice number as reference.
CHECK MADE PAYABLE TO: Box Inc, 900 Jefferson Ave, Redwood City, CA 94063, United States.
{{else}}

• The invoice must be paid must pay within 7 calendar days of the invoice date.
{{endif}}
Payment terms:

• The invoice must be paid within 60 calendar days of the invoice date.
• The payment reference should contain the invoice number as reference.
CHECK MADE PAYABLE TO: Box Inc, 900 Jefferson Ave, Redwood City, CA 94063, United States.
Adding processing fees based on invoice amount, and payment methodProcessing fees:

{{ if invoice.amount >  1000 AND invoice.amount < 5000 AND invoice.paymentMethod == “Cheque” }} 

• There will be an additional 1% processing fee that will be added to your account.
• The processing fee will be included to your next invoice.
{{ elseif invoice.amount > 5000 AND invoice.paymentMethod == “Cheque”}} 

• The invoice can be paid via check or online transfer without any added processing fees.
{{else}}

• The invoice must be paid within 7 calendar days of the invoice date.
{{endif}}
Processing fees:

• The invoice can be paid via check or online transfer without any added processing fees.
Adding delivery terms based on delivery date on invoiceDelivery terms:

{{ if invoice.deliveryDate isPresent }} 

• Your order shall be delivered on {{ invoice.deliveryDate}}.
• Orders delivered can be returned within 10 days of delivery.
{{else}}

• Your order shall be delivered within the next 7 days.
• Orders delivered can be returned within 10 days from the date of delivery.
Delivery terms:

• Your order will be delivered on 23-03-2023.
• Orders delivered can be returned within 10 days of delivery.

Conditions with tables

Doc Gen allows you to conditionally render any content including tables, images, and so on. {{ if invoice.customerId isPresent }}
IdNameQtyPrice
{{tablerow item in invoice.items}}
{{item.id}}{{item.name}}{{item.quantity}}{{item.price}}
{{endtablerow}}
{{ endif }}

Conditions inside tables

Doc Gen allows you to conditionally render content with a column in a table. Examples
IdNameQtyPrice
{{ tablerow item in invoice.items }}
{{ item.id}}{{ item.name}}{{ item.quantity}}{{ if item.price isPresent}}{{item.price}}{{ else }}-{{ endif }}
{{ endtablerow }}

6. Calculations

Box Doc Gen templates support dynamic calculations. You can either write the computation code to the tagging language manually, or use the Box Doc Gen Template Creator add-in.
Sample code calculations include:
  • Invoice: Determining the net invoice amount from individual line items.
    Example: Sum (Individual Line item amounts in the invoice)
  • Purchase order: Capping the maximum sourcing amount.
    Example: 5% * Net Order Value
  • Sales contracts: Defining penalty on SLA breach.
    Example: 10% * Total Sales Value
Supported operations
Arithmetic operationsAggregation operations
%Percent
+SUM
*AVERAGE
-COUNT
The following JSON serves as input for adding calculations to the document template.
{
  "invoice":{
    "number": "Inv1203",
    "invoiceDate": "13-03-2023, 12:10 PM",
    "deliveryDate": "23-03-2023",
    "customerId": "90158",
    "currency": "$",
    "taxRate": 3,
    "taxAmount": 151.8,
    "shippingCharge": 15,
    "grossAmount": 5060,
    "penaltyRate": 10,
    "billCap": 25,
    "items": [
      {
        "id": 1,
        "name": "A4 Papers",
        "quantity": 100,
        "price": 29,
        "amount": 2900
      },
      {
        "id": 2,
        "name": "Ink  cartridge",
        "quantity": 40,
        "price": 39,
        "amount": 1560
      },
      {
        "id": 3,
        "name": "Adhesive tape",
        "quantity": 20,
        "price": 30,
        "amount": 600
      }
    ]
  }
}
Examples:
Use caseDocument templateOutput document
To calculate net amount from the given Gross Amount and Tax Amount
Arithmetic calculation
Net Amount:
{{ invoice.grossAmount + invoice.taxAmount}}
Net Amount:
5211,8
Annotation:
5060 (grossAmount) + 151.8 (taxAmount)
To calculate net amount from the given Gross Amount, Tax Rate and Shipping Charge
Arithmetic calculation
Net Amount:
{{ invoice.grossAmount + invoice.taxAmount + invoice.shippingCharge}}
Net Amount:
5226.8
Annotation:
5060 (grossAmount) + 151.8 (taxAmount) + 15 (shippingCharge)
To calculate tax amount from the given Tax Rate and Gross Amount
Arithmetic calculation
Tax Amount:
{{ invoice.taxRate % * invoice.grossAmount}}
Tax Amount:
151.8
Annotation:
3% (taxRate)  * 5060 (grossAmount)
To calculate gross amount from individual line item amounts
Aggregation calculation
Gross Amount:
{{ $sum(invoice.items.amount) }}
Gross Amount:
5060
Annotation:
Sum (2900+1560+600)
To calculate number of line items
Count calculation
Count:
{{ $count(invoice.items.amount) }}
Count:
3
To calculate average of line itemsAverage Amount:
{{ $average(invoice.items.amount) }}
Average Amount:
1686.66
To calculate net amount from the given Line Item Amount, and Tax Rate 
Arithmetic + Aggregation calculation
Net Amount:
{{ sum(invoice.items.amount)+invoice.taxRatesum(invoice.items.amount) + invoice.taxRate % * sum(invoice.items.amount)}}
Net Amount:
5211,8
Annotation:
Sum (2900+1560+600) + 
3% * Sum (2900+1560+600)

7. Box Sign template tags

Box Sign template tags can be added to the Box Doc Gen template for the output document created via Box Box Doc Gen to be sent for e-signature. The table below lists the tags available in the Box Doc Gen Template Creator add-in and the tagging script.
FieldBox Sign’s template codeSupported 
via tagging script
Supported 
via add-in
Text field[[t|0]]YesYes
Date field[[d|0]]YesYes
Checkbox field[[c|0]]YesYes
Signature field[[s|0]]YesYes
Stamp field type[[st|0]]YesYes
Initials field type[[i|0]]YesYes
Name field type[[n|0]]YesYes
First name field type[[fn|0]]YesYes
Last name field type[[ln|0]]YesYes
Company field type[[co|0]]YesYes
Email field type[[e|0]]YesYes
Title field type[[ti|0]]YesYes
For an attachment field type[[a|0]]YesYes