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

# Template data

> Learn how to pre-populate template fields to automate your document templating.

## Overview

When creating or updating a signing package from a template, you can pre-populate template fields with specific data.
This allows for greater automation and customization of your document templates, ensuring that the generated documents contain
the necessary information without requiring manual input during the signing process.

## Steps

<Steps titleSize="h3">
  <Step title="Identify template fields">
    When adding a package, you can pre-populate templated fields in your documents by passing along template data values.
    This feature requires you to assign unique **data IDs** to each of the templated fields you want to set through our `template editor` or `templating tags`.

    <Tip>
      Currently only `text` and text `multiline` fields are supported.
    </Tip>

    ### Template editor

    Manually assign data IDs using the template editor in iinked Sign by selecting a field and setting the **Data ID** property in the field settings.

    ### Templating tags

    Alternatively, if you template your documents via templating tags, you can assign data IDs using the appropriate `id` tagging syntax.

    ```plaintext theme={null}
    {{s_1:text:id_text1}}
    {{s_1:multiline:id_multiline1}}
    ```

    See the [Template tags guide](/v4/guides/template-tagging/introduction) for more information.
  </Step>

  <Step title="Pre-populate template fields">
    When creating or updating a signing package using the `packages/add` or `packages/update` endpoints, you can pre-populate template fields by including the `templateData` object with each document in your request.

    Populate the `templateData` field of each document with a set of key/value pairs, with the key being the unique **data ID** value you assigned to your templated field.

    <Note>
      In the example below, the template requires a **text** field with a data ID of `text1`, and a text **multiline** field with a data ID of `multiline1`
    </Note>

    ```http Request highlight={28-31} theme={null}
    POST /packages/add
    {
        "type": "concurrent",
        "state": "open",
        "name": "From Template with Data",
        "templateId": "{{template_id}}",
        "signers": [
            {
                "templateRole": "Signer 1",
                "firstName": "Signer",
                "lastName": "One",
                "email": "{{signer_1_email}}",
                "mobileNumber": null
            }
        ],
        "recipients": [
            {
                "templateRole": "Recipient 1",
                "firstName": "Recipient",
                "lastName": "One",
                "email": "{{recipient_1_email}}",
                "mobileNumber": null
            }
        ],
        "documents": [
            {
                "templateDocumentId": "{{template_document_1_id}}",
                "templateData": {
                    "text1": "Set Text Field Value",
                    "multiline1": "Set Multiline Field Value Line 1\nSet Multiline Field Value Line 2"
                }
            }
        ]
    }
    ```
  </Step>

  <Step title="Retrieve template field data">
    After the signers have signed their documents and the package has been finalized you can retrieve the values of all fields in the
    package by calling the `/package/{packageId}/data` endpoint.

    ```http Request theme={null}
    GET /packages/{package_id}/data
    ```

    ```json Response expandable theme={null}
    {
        "packageId": "27acf4e5-8fef-4370-aea8-96c8c41fa6c2",
        "name": "Template Data Example",
        "type": "Sequential",
        "state": "open",
        "documents": [
            {
                "documentId": "f1c3d1a6-0430-4d0c-8140-2e33aead12d5",
                "packageId": "27acf4e5-8fef-4370-aea8-96c8c41fa6c2",
                "name": null,
                "fileName": "tags-data-id.pdf",
                "state": "open",
                "data": [
                    {
                        "id": "signer_1-text_1",
                        "dataId": "text1",
                        "signerId": "093bdc63-7e6c-450f-a423-7b294ad0901a",
                        "source": "template",
                        "type": "text",
                        "value": "text1-value-xxx",
                        "pageNumber": 1
                    },
                    {
                        "id": "signer_1-text_2",
                        "dataId": "text2",
                        "signerId": "093bdc63-7e6c-450f-a423-7b294ad0901a",
                        "source": "template",
                        "type": "text",
                        "value": "text2-value-yyy",
                        "pageNumber": 1
                    },
                    {
                        "id": "signer_1-text_3",
                        "dataId": "text3",
                        "signerId": "093bdc63-7e6c-450f-a423-7b294ad0901a",
                        "source": "template",
                        "type": "text",
                        "value": "text3-value-zzz",
                        "pageNumber": 1
                    },
                    {
                        "id": "signer_1-multiline_2",
                        "dataId": "multiline1",
                        "signerId": "093bdc63-7e6c-450f-a423-7b294ad0901a",
                        "source": "template",
                        "type": "multiline",
                        "value": "multiline1-value-xxx multiline1-value-yyy",
                        "pageNumber": 1
                    },
                    {
                        "id": "signer_2-text_4",
                        "dataId": "text4",
                        "signerId": "7d9c2386-8979-4f1f-afd9-2a51eb4a3193",
                        "source": "template",
                        "type": "text",
                        "value": "text4-value-xxx",
                        "pageNumber": 1
                    },
                    {
                        "id": "signer_2-text_5",
                        "dataId": "text5",
                        "signerId": "7d9c2386-8979-4f1f-afd9-2a51eb4a3193",
                        "source": "template",
                        "type": "text",
                        "value": "text5-value-yyy",
                        "pageNumber": 1
                    }
                ]
            }
        ]
    }
    ```
  </Step>
</Steps>
