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

# Generate documents

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = localizeLink(href);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

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 <Link href="/guides/docgen/docgen-getting-started">get started with Box Doc Gen</Link> guide to create a platform 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**.

| Parameter                                          | Description                                                                                                            | Example                                                      |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| **`file.id`**                                      | ID of the file to be marked as Box Doc Gen template.                                                                   | `12345678`                                                   |
| **`file.type`**                                    | The type of provided input. The value is always **`file`**.                                                            | `file`                                                       |
| `file_version`                                     | The file version of a template.                                                                                        | `12345`                                                      |
| **`input_source`**                                 | The input source for generated document. The value has to be `api` for all the API-based document generation requests. | `api`                                                        |
| **`output_type`**                                  | The output file type.                                                                                                  | `docx`, `pdf`                                                |
| **`destination_folder.id`**                        | The ID of the folder where the generated document will be stored.                                                      | `12345678`                                                   |
| **`destination_folder.type`**                      | The type of the destination item. Since the generated files are stored in folders, the value is always **`folder`**.   | `file`                                                       |
| **`document_generation_data.generated_file_name`** | The name of the generated file.                                                                                        | `New_Template`                                               |
| **`document_generation_data.user_input`**          | The 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:

<CodeGroup>
  ```sh cURL theme={null}
  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
                              }
                          ]
                      }
                  }
              }
          ]`
  ```

  ```typescript Node/TypeScript v10 theme={null}
  await client.docgen.createDocgenBatchV2025R0({
    file: new FileReferenceV2025R0({ id: uploadedFile.id }),
    inputSource: 'api',
    destinationFolder: new DocGenBatchCreateRequestV2025R0DestinationFolderField({
      id: folder.id,
    }),
    outputType: 'pdf',
    documentGenerationData: [
      {
        generatedFileName: 'test',
        userInput: { ['abc']: 'xyz' },
      } satisfies DocGenDocumentGenerationDataV2025R0,
    ],
  } satisfies DocGenBatchCreateRequestV2025R0);
  ```

  ```python Python v10 theme={null}
  client.docgen.create_docgen_batch_v2025_r0(
      FileReferenceV2025R0(id=uploaded_file.id),
      "api",
      CreateDocgenBatchV2025R0DestinationFolder(id=folder.id),
      "pdf",
      [
          DocGenDocumentGenerationDataV2025R0(
              generated_file_name="test", user_input={"abc": "xyz"}
          )
      ],
  )
  ```

  ```cs .NET v10 theme={null}
  await client.Docgen.CreateDocgenBatchV2025R0Async(requestBody: new DocGenBatchCreateRequestV2025R0(file: new FileReferenceV2025R0(id: uploadedFile.Id), inputSource: "api", destinationFolder: new DocGenBatchCreateRequestV2025R0DestinationFolderField(id: folder.Id), outputType: "pdf", documentGenerationData: Array.AsReadOnly(new [] {new DocGenDocumentGenerationDataV2025R0(generatedFileName: "test", userInput: new Dictionary<string, object>() { { "abc", "xyz" } })})));
  ```

  ```swift Swift v10 theme={null}
  try await client.docgen.createDocgenBatchV2025R0(requestBody: DocGenBatchCreateRequestV2025R0(file: FileReferenceV2025R0(id: uploadedFile.id), inputSource: "api", destinationFolder: DocGenBatchCreateRequestV2025R0DestinationFolderField(id: folder.id), outputType: "pdf", documentGenerationData: [DocGenDocumentGenerationDataV2025R0(generatedFileName: "test", userInput: ["abc": "xyz"])]))
  ```

  ```java Java v10 theme={null}
  client.getDocgen().createDocgenBatchV2025R0(new DocGenBatchCreateRequestV2025R0(new FileReferenceV2025R0(uploadedFile.getId()), "api", new DocGenBatchCreateRequestV2025R0DestinationFolderField(folder.getId()), "pdf", Arrays.asList(new DocGenDocumentGenerationDataV2025R0("test", mapOf(entryOf("abc", "xyz"))))))
  ```
</CodeGroup>

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.

<RelatedLinks
  title="RELATED GUIDES"
  items={[
{ label: translate("Get started with Box Doc Gen"), href: "/guides/docgen/docgen-getting-started", badge: "GUIDE" },
{ label: translate("Mark file as Box Doc Gen template"), href: "/guides/docgen/mark-template", badge: "GUIDE" }
]}
/>
