Box Developer Documentation
 

    Generate documents

    Generate documents

    The POST /2.0/docgen_batches endpoint allows you to generate a document using Box Doc Gen template as input.

    Prerequisites

    Before you start using Box Doc Gen API, follow the steps listed in the get started with Box Doc Gen guide to create a custom app and a Box Doc Gen template.

    Send a request

    To generate a document or a set of documents, use the POST /2.0/docgen_batches endpoint.

    Parameters

    To make a call, you need to pass the following parameters. Mandatory parameters are in bold.

    ParameterDescriptionExample
    file.idID of the file to be marked as Box Doc Gen template.12345678
    file.typeThe type of provided input. The value is always file.file
    file_versionThe file version of a template.12345
    input_sourceThe input source for generated document. The value has to be api for all the API-based document generation requests.api
    output_typeThe output file type.docx
    destination_folder.idThe ID of the folder where the generated document will be stored.12345678
    destination_folder.typeThe type of the destination item. Since the generated files are stored in folders, the value is always folder.file
    document_generation_data.generated_file_nameThe name of the generated file.New_Template
    document_generation_data.user_inputThe JSON data to be used to generate document.{"id": 2, "name": "Ink Cartridge", "type": "non-fragile"}

    Use case

    When your Box Doc Gen template and JSON data is ready, you can make a request to Box Doc Gen API to generate documents.

    A sample call looks as follows:

    cURL
    curl -L 'https://api.box.com/2.0/docgen_batches' \
         -H 'box-version: 2025.0' \
         -H 'Authorization: Bearer <ACCESS_TOKEN>' \
         -D '{
            "file": {
                "id": "12345678",
                "type": "file"
            },
            "input_source": "api",
            "destination_folder": {
                "id": "12345678",
                "type": "folder"
            },
            "output_type": "docx",
            "document_generation_data": [
                {
                    "generated_file_name": "Image test",
                    "user_input": {
                        "order": {
                            "id": "12305",
                            "date": "18-08-2023",
                            "country": "US",
                            "expiryDate": "18-08-2024",
                            "currency": "$",
                            "amount": 5060.5,
                            "taxRate": 10,
                            "requester": "John",
                            "approver": "Smith",
                            "department": "Procurement",
                            "paymentTerms": "30 days",
                            "deliveryTerms": "30 days",
                            "deliveryDate": "18-09-2023",
                            "vendor": {
                                "company": "Example company",
                                "address": {
                                    "street": "Example street",
                                    "city": "Example city",
                                    "zip": "EX-456"
                                }
                            },
                            "products": [
                                {
                                    "id": 1,
                                    "name": "A4 Papers",
                                    "type": "non-fragile",
                                    "quantity": 100,
                                    "price": 29,
                                    "amount": 2900
                                },
                                {
                                    "id": 2,
                                    "name": "Ink  Cartridge",
                                    "type": "non-fragile",
                                    "quantity": 40,
                                    "price": 39,
                                    "amount": 1560
                                },
                                {
                                    "id": 3,
                                    "name": "Adhesive tape",
                                    "type": "non-fragile",
                                    "quantity": 20,
                                    "price": 30,
                                    "amount": 600.5
                                }
                            ]
                        }
                    }
                }
            ]`

    When the request is being processed, each entry in the document_generation_data array is treated as a separate document generation job that Box Doc Gen adds to the document generation queue.

    Generated documents will be saved in the designated folder.