> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to create a template

> Demonstrates how to create a new template programmatically.

This topic demonstrates how to create a template.

> **Note**
>
> Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects: [Bash](https://github.com/docusign/code-examples-bash), [C#](https://github.com/docusign/code-examples-csharp), [Java](https://github.com/docusign/code-examples-java), [Node.js](https://github.com/docusign/code-examples-node), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).

## Required data

Running the code in this how-to requires this data:

| Data element          | Description                                                                                                                                                                                                                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{API_ACCOUNT_ID}     | A [GUID](http://guid.one/) value that identifies your account. This value is automatically generated by Docusign for any account you create. Copy the value from the **API Account ID** field on the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) page.                               |
| \{BASE_PATH}          | A string value that forms the root of the URL required to make API calls. The base path value in the example code is set to target the developer environment at https\://\<domain>/restapi Where \<domain> is demo.docusign.net for the developer environment and is the result of the GetUserInfo call in production. |
| \{DOCS_PATH}          | A string value for the file path to the folder containing the documents you want to include in the [envelope](/docs/esign-rest-api/esign101/concepts/envelopes).                                                                                                                                                       |
| Document to be signed | You must provide at least one document to be signed. Document used in this how-to:- [PDF file](https://github.com/docusign/code-examples-java/blob/master/src/main/resources/World_Wide_Corp_lorem.pdf)                                                                                                                |
| \{TEMPLATE_NAME}      | The template name should be set to "Example Signer and CC template" for this example.                                                                                                                                                                                                                                  |

## Step 1. Obtain your OAuth token

To make the API call shown in this how-to, you need a valid OAuth access token. Docusign supports access tokens for three different recommended OAuth grant types: Public Authorization Code Grant, Confidential Authorization Code Grant, and JSON Web Token (JWT) Grant. Choose the OAuth grant type appropriate for your scenario.

> **Note**
>
> See [Confidential Authorization Code Grant](/platform/auth/authcode#confidential-authorization-code-grant) for guidance on your options to get an Confidential Authorization Code Grant  OAuth token.

![Three icons that represent the three methods a user can use to obtain an OAuth token: JSON Web Token (JWT), Public Authorization Code Grant (ACG), and Confidential Authorization Code grant](/_fern-files/_img/64f473773042ee439449a096bf7673292b1585b86a4ccc55f82ba0dda41f61a1.webp)

## Step 2. Create a template

* Create a new template definition.

  * Add a document to the definition by saving it to a variable as a base64 string. If you intend to attach multiple documents, specify the document order using an array. The order of the array will be the document order.
  * Create role placeholders for your recipients. For this template, we are assigning placeholders to a 'Signer' role and a carbon copy 'CC' role. These placeholder roles contain an ID, a role name, and a routing order that determines the order of delivery.
  * Create and assign signable fields (also known as tabs) for each specific signer within the document. This code example uses absolute positioning to set each tab a specific number of points from the corner of the screen.
  * Set the template definition data, including a description, name, email subject, recipients, and [status](/docs/esign-rest-api/reference/envelopes/envelopes/liststatus).
* Create the template object from your definition using the [Templates:create](/docs/esign-rest-api/reference/templates/templates/create) method.

**`Bash`**

```bash title="Bash"
printf \
'{
    "description": "Example template created via the API",
    "name": "Example Signer and CC template v2",
    "shared": "false",
    "documents": [
        {
            "documentBase64": "' > $request_data
            cat $doc1_base64 >> $request_data
            printf '",
            "documentId": "1", "fileExtension": "pdf",
            "name": "Lorem Ipsum"
        }
    ],
    "emailSubject": "Please sign this document",
   "recipients": {
        "carbonCopies": [
            {"recipientId": "2", "roleName": "cc", "routingOrder": "2"}
        ],
        "signers": [
            {
                "recipientId": "1", "roleName": "signer", "routingOrder": "1",
                "tabs": {
                    "checkboxTabs": [
                        {
                            "documentId": "1", "pageNumber": "1",
                            "tabLabel": "ckAuthorization", "xPosition": "75",
                            "yPosition": "417"
                        },
                        {
                            "documentId": "1", "pageNumber": "1",
                            "tabLabel": "ckAuthentication", "xPosition": "75",
                            "yPosition": "447"
                        },
                        {
                            "documentId": "1", "pageNumber": "1",
                            "tabLabel": "ckAgreement", "xPosition": "75",
                            "yPosition": "478"
                        },
                        {
                            "documentId": "1", "pageNumber": "1",
                            "tabLabel": "ckAcknowledgement", "xPosition": "75",
                            "yPosition": "508"
                        }
                    ],
                    "listTabs": [
                        {
                            "documentId": "1", "font": "helvetica",
                            "fontSize": "size14",
                            "listItems": [
                                {"text": "Red", "value": "red"},
                                {"text": "Orange", "value": "orange"},
                                {"text": "Yellow", "value": "yellow"},
                                {"text": "Green", "value": "green"},
                                {"text": "Blue", "value": "blue"},
                                {"text": "Indigo", "value": "indigo"},
                                {"text": "Violet", "value": "violet"}
                            ],
                            "pageNumber": "1", "required": "false",
                            "tabLabel": "list", "xPosition": "142",
                            "yPosition": "291"
                        }
                    ],
                    "radioGroupTabs": [
                        {
                            "documentId": "1", "groupName": "radio1",
                            "radios": [
                                {
                                    "pageNumber": "1", "required": "false",
                                    "value": "white", "xPosition": "142",
                                    "yPosition": "384"
                                },
                                {
                                    "pageNumber": "1", "required": "false",
                                    "value": "red", "xPosition": "74",
                                    "yPosition": "384"
                                },
                                {
                                    "pageNumber": "1", "required": "false",
                                    "value": "blue", "xPosition": "220",
                                    "yPosition": "384"
                                }
                            ]
                        }
                    ],
                    "signHereTabs": [
                        {
                            "documentId": "1", "pageNumber": "1",
                            "xPosition": "191", "yPosition": "148"
                        }
                    ],
                    "textTabs": [
                        {
                            "documentId": "1", "font": "helvetica",
                            "fontSize": "size14", "height": 23,
                            "pageNumber": "1", "required": "false",
                            "tabLabel": "text", "width": 84,
                            "xPosition": "153", "yPosition": "230"
                        }
                    ],
                    "numericalTabs" : [
                        {
                            "validationType": "Currency",
                            "documentId": "1", "font": "helvetica",
                            "fontSize": "size14", "height": 23,
                            "pageNumber": "1", "required": "false",
                            "tabLabel": "numericalCurrency", "width": 84,
                            "xPosition": "153", "yPosition": "260"
                        }]
                }
            }
        ]
    },
    "status": "created"
}' >> $request_data
```

**`C#`**

```csharp title="C#"
Document doc = new Document();
string docB64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(documentPdf));
doc.DocumentBase64 = docB64;
doc.Name = "Lorem Ipsum"; // can be different from actual file name
doc.FileExtension = "pdf";
doc.DocumentId = "1";

// create a signer recipient to sign the document, identified by name and email
// We're setting the parameters via the object creation
Signer signer1 = new Signer();
signer1.RoleName = "signer";
signer1.RecipientId = "1";
signer1.RoutingOrder = "1";

// routingOrder (lower means earlier) determines the order of deliveries
// to the recipients. Parallel routing order is supported by using the
// same integer as the order for two or more recipients.

// create a cc recipient to receive a copy of the documents, identified by name and email
// We're setting the parameters via setters
CarbonCopy cc1 = new CarbonCopy();
cc1.RoleName = "cc";
cc1.RoutingOrder = "2";
cc1.RecipientId = "2";

// Create fields using absolute positioning:
SignHere signHere = new SignHere();
signHere.DocumentId = "1";
signHere.PageNumber = "1";
signHere.XPosition = "191";
signHere.YPosition = "148";

Checkbox check1 = new Checkbox();
check1.DocumentId = "1";
check1.PageNumber = "1";
check1.XPosition = "75";
check1.YPosition = "417";
check1.TabLabel = "ckAuthorization";

Checkbox check2 = new Checkbox();
check2.DocumentId = "1";
check2.PageNumber = "1";
check2.XPosition = "75";
check2.YPosition = "447";
check2.TabLabel = "ckAuthentication";

Checkbox check3 = new Checkbox();
check3.DocumentId = "1";
check3.PageNumber = "1";
check3.XPosition = "75";
check3.YPosition = "478";
check3.TabLabel = "ckAgreement";

Checkbox check4 = new Checkbox();
check4.DocumentId = "1";
check4.PageNumber = "1";
check4.XPosition = "75";
check4.YPosition = "508";
check4.TabLabel = "ckAcknowledgement";

List list1 = new List();
list1.DocumentId = "1";
list1.PageNumber = "1";
list1.XPosition = "142";
list1.YPosition = "291";
list1.Font = "helvetica";
list1.FontSize = "size14";
list1.TabLabel = "list";
list1.Required = "false";
list1.ListItems = new List<ListItem>
{
    new ListItem { Text = "Red", Value = "Red" },
    new ListItem { Text = "Orange", Value = "Orange" },
    new ListItem { Text = "Yellow", Value = "Yellow" },
    new ListItem { Text = "Green", Value = "Green" },
    new ListItem { Text = "Blue", Value = "Blue" },
    new ListItem { Text = "Indigo", Value = "Indigo" },
    new ListItem { Text = "Violet", Value = "Violet" },
};

Numerical numerical = new Numerical();
numerical.ValidationType = "Currency";
numerical.DocumentId = "1";
numerical.PageNumber = "1";
numerical.XPosition = "153";
numerical.YPosition = "260";
numerical.Font = "helvetica";
numerical.FontSize = "size14";
numerical.TabLabel = "numericalCurrency";
numerical.Height = "23";
numerical.Width = "84";
numerical.Required = "false";

RadioGroup radioGroup = new RadioGroup();
radioGroup.DocumentId = "1";
radioGroup.GroupName = "radio1";

radioGroup.Radios = new List<Radio>
{
    new Radio { PageNumber = "1", Value = "white", XPosition = "142", YPosition = "384", Required = "false" },
    new Radio { PageNumber = "1", Value = "red", XPosition = "74", YPosition = "384", Required = "false" },
    new Radio { PageNumber = "1", Value = "blue", XPosition = "220", YPosition = "384", Required = "false" },
};

Text text = new Text();
text.DocumentId = "1";
text.PageNumber = "1";
text.XPosition = "153";
text.YPosition = "230";
text.Font = "helvetica";
text.FontSize = "size14";
text.TabLabel = "text";
text.Height = "23";
text.Width = "84";
text.Required = "false";

// Tabs are set per recipient / signer
Tabs signer1Tabs = new Tabs();
signer1Tabs.CheckboxTabs = new List<Checkbox>
{
    check1, check2, check3, check4,
};

signer1Tabs.ListTabs = new List<List> { list1 };

// numberTabs: [number],
signer1Tabs.RadioGroupTabs = new List<RadioGroup> { radioGroup };
signer1Tabs.SignHereTabs = new List<SignHere> { signHere };
signer1Tabs.TextTabs = new List<Text> { text };
signer1Tabs.NumericalTabs = new List<Numerical> { numerical };

signer1.Tabs = signer1Tabs;

// Add the recipients to the env object
Recipients recipients = new Recipients();
recipients.Signers = new List<Signer> { signer1 };
recipients.CarbonCopies = new List<CarbonCopy> { cc1 };

// create the overall template definition
EnvelopeTemplate template = new EnvelopeTemplate();

// The order in the docs array determines the order in the env
template.Description = "Example template created via the API";
template.Name = resultsTemplateName;
template.Documents = new List<Document> { doc };
template.EmailSubject = "Please sign this document";
template.Recipients = recipients;
template.Status = "created";
```

**`Java`**

```java title="Java"
public static EnvelopeTemplate makeTemplate(String templateName) throws IOException {
    Document doc = EnvelopeHelpers.createDocumentFromFile(PDF_DOCUMENT_FILE_NAME, PDF_DOCUMENT_NAME, "1");

    // Tabs are set per recipient / signer
    Tabs signer1Tabs = new Tabs();
    signer1Tabs.setCheckboxTabs(Arrays.asList(
            createCheckbox("ckAuthorization", "75", "417"),
            createCheckbox("ckAuthentication", "75", "447"),
            createCheckbox("ckAgreement", "75", "478"),
            createCheckbox("ckAcknowledgement", "75", "508")));
    signer1Tabs.setListTabs(Collections.singletonList(createList()));
    signer1Tabs.setRadioGroupTabs(Collections.singletonList(createRadioGroup()));
    signer1Tabs.setSignHereTabs(Collections.singletonList(createSignHere()));
    signer1Tabs.textTabs(java.util.List.of(
            createText("text", "153", "230")));
    signer1Tabs.numericalTabs(java.util.List.of(
            createNumerical("numericalCurrency", "153", "260")));

    // create a signer recipient to sign the document, identified by name and email
    // routingOrder (lower means earlier) determines the order of deliveries
    // to the recipients. Parallel routing order is supported by using the
    // same integer as the order for two or more recipients.
    Signer signer = new Signer();
    signer.setRoleName(EnvelopeHelpers.SIGNER_ROLE_NAME);
    signer.setRecipientId("1");
    signer.setRoutingOrder("1");
    signer.setTabs(signer1Tabs);

    // create a cc recipient to receive a copy of the documents, identified by name
    // and email
    CarbonCopy cc1 = new CarbonCopy();
    cc1.setRoleName(EnvelopeHelpers.CC_ROLE_NAME);
    cc1.setRoutingOrder("2");
    cc1.setRecipientId("2");

    // Create the overall template definition. The order in the docs array
    // determines the order in the envelope.
    EnvelopeTemplate template = new EnvelopeTemplate();
    template.setDocuments(Collections.singletonList(doc));
    template.setEmailSubject("Please sign this document");
    template.setName(templateName);
    template.setDescription("Example template created via the API");
    template.setShared(FALSE);
    template.setRecipients(EnvelopeHelpers.createRecipients(signer, cc1));
    template.setStatus(EnvelopeHelpers.ENVELOPE_STATUS_CREATED);

    return template;
}

public static List createList() {
    List list = new List();
    list.setDocumentId(DOCUMENT_ID);
    list.setPageNumber(PAGE_NUMBER);
    list.setXPosition("142");
    list.setYPosition("291");
    list.setFont("helvetica");
    list.setFontSize("size14");
    list.setTabLabel("list");
    list.setRequired(FALSE);
    list.setListItems(Arrays.asList(
            createListItem("Red"),
            createListItem("Orange"),
            createListItem("Yellow"),
            createListItem("Green"),
            createListItem("Blue"),
            createListItem("Indigo"),
            createListItem("Violet")));
    return list;
}

public static ListItem createListItem(String color) {
    ListItem item = new ListItem();
    item.setText(color);
    item.setValue(color.toLowerCase(Locale.ENGLISH));
    return item;
}

public static RadioGroup createRadioGroup() {
    RadioGroup radioGroup = new RadioGroup();
    radioGroup.setDocumentId(DOCUMENT_ID);
    radioGroup.setGroupName("radio1");

    radioGroup.setRadios(Arrays.asList(
            createRadio("white", "142"),
            createRadio("red", "74"),
            createRadio("blue", "220")));
    return radioGroup;
}

public static Radio createRadio(String value, String xPosition) {
    Radio radio = new Radio();
    radio.setPageNumber(PAGE_NUMBER);
    radio.setValue(value);
    radio.setXPosition(xPosition);
    radio.setYPosition("384");
    radio.setRequired(FALSE);
    return radio;
}

public static Checkbox createCheckbox(String label, String xPosition, String yPosition) {
    Checkbox check = new Checkbox();
    check.setDocumentId(DOCUMENT_ID);
    check.setPageNumber(PAGE_NUMBER);
    check.setXPosition(xPosition);
    check.setYPosition(yPosition);
    check.setTabLabel(label);
    return check;
}

public static Text createText(String label, String xPosition, String yPosition) {
    Text text = new Text();
    text.setDocumentId(DOCUMENT_ID);
    text.setPageNumber(PAGE_NUMBER);
    text.setXPosition(xPosition);
    text.setYPosition(yPosition);
    text.setFont("helvetica");
    text.setFontSize("size14");
    text.setTabLabel(label);
    text.setHeight("23");
    text.setWidth("84");
    text.setRequired(FALSE);
    return text;
}

public static Numerical createNumerical(String label, String xPosition, String yPosition) {
    Numerical numerical = new Numerical();
    numerical.setValidationType("Currency");
    numerical.setDocumentId(DOCUMENT_ID);
    numerical.setPageNumber(PAGE_NUMBER);
    numerical.setXPosition(xPosition);
    numerical.setYPosition(yPosition);
    numerical.setFont("helvetica");
    numerical.setFontSize("size14");
    numerical.setTabLabel(label);
    numerical.setHeight("23");
    numerical.setWidth("84");
    numerical.setRequired(FALSE);
    return numerical;
}

public static SignHere createSignHere() {
    SignHere signHere = new SignHere();
    signHere.setDocumentId(DOCUMENT_ID);
    signHere.setPageNumber(PAGE_NUMBER);
    signHere.setXPosition("191");
    signHere.setYPosition("148");
    return signHere;
}
```

**`Node.js`**

```javascript title="Node.js"
function makeTemplate(args) {
  // Data for this method
  // demoDocsPath -- module global
  // docFile -- module global
  // templateName -- module global

  // document 1 (pdf) has tag /sn1/
  //
  // The template has two recipient roles.
  // recipient 1 - signer
  // recipient 2 - cc
  // The template will be sent first to the signer.
  // After it is signed, a copy is sent to the cc person.

  let docPdfBytes;
  // read file from a local directory
  // The reads could raise an exception if the file is not available!
  docPdfBytes = fs.readFileSync(args.docFile);

  // add the documents
  let doc = new docusign.Document();
    let docB64 = Buffer.from(docPdfBytes).toString('base64');
  doc.documentBase64 = docB64;
  doc.name = 'Lorem Ipsum'; // can be different from actual file name
  doc.fileExtension = 'pdf';
  doc.documentId = '1';

  // create a signer recipient to sign the document, identified by name and email
  // We're setting the parameters via the object creation
  let signer1 = docusign.Signer.constructFromObject({
    roleName: 'signer',
    recipientId: '1',
    routingOrder: '1',
  });
  // routingOrder (lower means earlier) determines the order of deliveries
  // to the recipients. Parallel routing order is supported by using the
  // same integer as the order for two or more recipients.

  // create a cc recipient to receive a copy of the documents, identified by name and email
  // We're setting the parameters via setters
  let cc1 = new docusign.CarbonCopy();
  cc1.roleName = 'cc';
  cc1.routingOrder = '2';
  cc1.recipientId = '2';

  // Create fields using absolute positioning:
  let signHere = docusign.SignHere.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '191',
      yPosition: '148',
    });
    let check1 = docusign.Checkbox.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '75',
      yPosition: '417',
      tabLabel: 'ckAuthorization',
    });
    let check2 = docusign.Checkbox.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '75',
      yPosition: '447',
      tabLabel: 'ckAuthentication',
    });
    let check3 = docusign.Checkbox.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '75',
      yPosition: '478',
      tabLabel: 'ckAgreement',
    });
    let check4 = docusign.Checkbox.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '75',
      yPosition: '508',
      tabLabel: 'ckAcknowledgement',
    });
    let list1 = docusign.List.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '142',
      yPosition: '291',
      font: 'helvetica',
      fontSize: 'size14',
      tabLabel: 'list',
      required: 'false',
      listItems: [
        docusign.ListItem.constructFromObject({ text: 'Red', value: 'red' }),
        docusign.ListItem.constructFromObject({
          text: 'Orange',
          value: 'orange',
        }),
        docusign.ListItem.constructFromObject({
          text: 'Yellow',
          value: 'yellow',
        }),
        docusign.ListItem.constructFromObject({
          text: 'Green',
          value: 'green',
        }),
        docusign.ListItem.constructFromObject({ text: 'Blue', value: 'blue' }),
        docusign.ListItem.constructFromObject({
          text: 'Indigo',
          value: 'indigo',
        }),
        docusign.ListItem.constructFromObject({
          text: 'Violet',
          value: 'violet',
        }),
      ],
    });
    let numerical = docusign.Numerical.constructFromObject({
            validationType: 'Currency',
            documentId: '1',
            pageNumber: '1',
            xPosition: '163',
            yPosition: '260',
            font: 'helvetica',
            fontSize: 'size14',
            tabLabel: 'numericalCurrency',
            height: '23',
            width: '84',
            required: 'false'});
    let radioGroup = docusign.RadioGroup.constructFromObject({
      documentId: '1',
      groupName: 'radio1',
      radios: [
        docusign.Radio.constructFromObject({
          font: 'helvetica',
          fontSize: 'size14',
          pageNumber: '1',
          value: 'white',
          xPosition: '142',
          yPosition: '384',
          required: 'false',
        }),
        docusign.Radio.constructFromObject({
          font: 'helvetica',
          fontSize: 'size14',
          pageNumber: '1',
          value: 'red',
          xPosition: '74',
          yPosition: '384',
          required: 'false',
        }),
        docusign.Radio.constructFromObject({
          font: 'helvetica',
          fontSize: 'size14',
          pageNumber: '1',
          value: 'blue',
          xPosition: '220',
          yPosition: '384',
          required: 'false',
        }),
      ],
    });
    let text = docusign.Text.constructFromObject({
      documentId: '1',
      pageNumber: '1',
      xPosition: '153',
      yPosition: '230',
      font: 'helvetica',
      fontSize: 'size14',
      tabLabel: 'text',
      height: '23',
      width: '84',
      required: 'false',
    });
  // Tabs are set per recipient / signer
  let signer1Tabs = docusign.Tabs.constructFromObject({
    checkboxTabs: [check1, check2, check3, check4],
    listTabs: [list1],
    numericalTabs: [numerical],
    radioGroupTabs: [radioGroup],
    signHereTabs: [signHere],
    textTabs: [text],
  });
  signer1.tabs = signer1Tabs;

  // Add the recipients to the env object
  let recipients = docusign.Recipients.constructFromObject({
    signers: [signer1],
    carbonCopies: [cc1],
  });

  // create the overall template definition
  let template = new docusign.EnvelopeTemplate.constructFromObject({
    // The order in the docs array determines the order in the env
    documents: [doc],
    emailSubject: 'Please sign this document',
    description: 'Example template created via the API',
    name: args.templateName,
    shared: 'false',
    recipients: recipients,
    status: 'created',
  });

  return template;
}
```

**`PHP`**

```php title="PHP"
public static function makeTemplateRequest($template_name, $demoDocsPath): EnvelopeTemplate
{
    # document 1 is a pdf
    #
    # The template has two recipient roles.
    # recipient 1 - signer
    # recipient 2 - cc
    #
    # Read the pdf from the disk
    # read files 2 and 3 from a local directory
    # The reads could raise an exception if the file is not available!
    $doc_file = 'World_Wide_Corp_fields.pdf';
    $content_bytes = file_get_contents($demoDocsPath . $doc_file);
    $base64_file_content = base64_encode($content_bytes);

    # Create the document model
    $document = new Document([  # create the DocuSign document object
        'document_base64' => $base64_file_content,
        'name' => 'Lorem Ipsum',  # can be different from actual file name
        'file_extension' => 'pdf',  # many different document types are accepted
        'document_id' => '1'  # a label used to reference the doc
    ]);

    # Create the signer recipient model
    # Since these are role definitions, no name/email:
    $signer = new Signer([
        'role_name' => 'signer', 'recipient_id' => "1", 'routing_order' => "1"]);
    # create a cc recipient to receive a copy of the documents
    $cc = new CarbonCopy([
        'role_name' => 'cc', 'recipient_id' => "2", 'routing_order' => "2"]);
    # Create fields using absolute positioning
    # Create a sign_here tab (field on the document)
    $sign_here = new SignHere(['document_id' => '1', 'page_number' => '1',
                                  'x_position' => '191',
                                  'y_position' => '148'
                              ]);
    $check1 = new Checkbox(
        [
            'document_id' => '1',
            'page_number' => '1',
            'x_position' => '75',
            'y_position' => '417',
            'tab_label' => 'ckAuthorization'
        ]
    );
    $check2 = new Checkbox(
        [
            'document_id' => '1',
            'page_number' => '1',
            'x_position' => '75',
            'y_position' => '447',
            'tab_label' => 'ckAuthentication'
        ]
    );
    $check3 = new Checkbox(
        [
            'document_id' => '1',
            'page_number' => '1',
            'x_position' => '75',
            'y_position' => '478',
            'tab_label' => 'ckAgreement'
        ]
    );
    $check4 = new Checkbox(
        [
            'document_id' => '1',
            'page_number' => '1',
            'x_position' => '75',
            'y_position' => '508',
            'tab_label' => 'ckAcknowledgement'
        ]
    );

    $list1 = CreateTemplateService::createListOfButtonOptions();

    $numerical = new Numerical(
        [
            'document_id' => "1",
            'validation_type' => "Currency",
            'page_number' => "1",
            'x_position' => "163",
            'y_position' => "260",
            'font' => "helvetica",
            'font_size' => "size14",
            'tab_label' => "numericalCurrency",
            'width' => "84",
            'required' => "false"
        ]
    );
    $radio_group = new RadioGroup(
        [
            'document_id' => "1",
            'group_name' => "radio1",
            'radios' => [
                new Radio(
                    [
                        'page_number' => "1",
                        'x_position' => "142",
                        'y_position' => "384",
                        'value' => "white",
                        'required' => "false"
                    ]
                ),
                new Radio(
                    [
                        'page_number' => "1",
                        'x_position' => "74",
                        'y_position' => "384",
                    'value' => "red",
                    'required' => "false"]
                ),
            new Radio(['page_number' => "1", 'x_position' => "220", 'y_position' => "384",
                'value' => "blue", 'required' => "false"])
            ]]
    );
    $text = new Text(['document_id' => "1", 'page_number' => "1",
        'x_position' => "153", 'y_position' => "230",
        'font' => "helvetica", 'font_size' => "size14", 'tab_label' => "text",
        'height' => "23", 'width' => "84", 'required' => "false"]);
    # Add the tabs model to the signer
    # The Tabs object wants arrays of the different field/tab types
    $signer->setTabs(new Tabs(['sign_here_tabs' => [$sign_here],
        'checkbox_tabs' => [$check1, $check2, $check3, $check4], 'list_tabs' => [$list1],
        'numerical_tabs' => [$numerical], 'radio_group_tabs' => [$radio_group], 'text_tabs' => [$text]
    ]));

    # Template object:
    return new EnvelopeTemplate(
        [
            'description' => "Example template created via the API",
            'name' => $template_name,
            'shared' => "false",
            'documents' => [$document],
            'email_subject' => "Please sign this document",
            'recipients' => new Recipients(
                [
                    'signers' => [$signer],
                    'carbon_copies' => [$cc]
                ]
            ),
            'status' => "created"
        ]
    );
}
```

**`PowerShell`**

```text title="PowerShell"
@{
    description = "Example template created via the eSignature API";
    name        = "Example Signer and CC template v2";
    shared      = "false";
    documents                  = @(
        @{
            documentBase64 = "$(Get-Content $doc1Base64)";
            documentId     = "1";
            fileExtension  = "pdf";
            name           = "Lorem Ipsum";
        };
    );
    emailSubject               = "Please sign this document";
    recipients                 = @{
        carbonCopies = @(
            @{recipientId = "2"; roleName = "cc"; routingOrder = "2"; };
        );
        signers      = @(
            @{
                recipientId = "1"; roleName = "signer"; routingOrder = "1";
                tabs = @{
                    checkboxTabs   = @(
                        @{
                            documentId = "1"; pageNumber = "1";
                            tabLabel = "ckAuthorization"; xPosition = "75";
                            yPosition = "417";
                        };
                        @{
                            documentId = "1"; pageNumber = "1";
                            tabLabel = "ckAuthentication"; xPosition = "75";
                            yPosition = "447";
                        };
                        @{
                            documentId = "1"; pageNumber = "1";
                            tabLabel = "ckAgreement"; xPosition = "75";
                            yPosition = "478";
                        };
                        @{
                            documentId = "1"; pageNumber = "1";
                            tabLabel = "ckAcknowledgement"; xPosition = "75";
                            yPosition = "508";
                        };
                    );
                    listTabs       = @(
                        @{
                            documentId = "1"; font = "helvetica";
                            fontSize = "size14";
                            listItems = @(
                                @{text = "Red"; value = "red"; };
                                @{text = "Orange"; value = "orange"; };
                                @{text = "Yellow"; value = "yellow"; };
                                @{text = "Green"; value = "green"; };
                                @{text = "Blue"; value = "blue"; };
                                @{text = "Indigo"; value = "indigo"; };
                                @{text = "Violet"; value = "violet"; };
                            );
                            pageNumber = "1"; required = "false";
                            tabLabel = "list"; xPosition = "142";
                            yPosition = "291";
                        };
                    );
                    radioGroupTabs = @(
                        @{
                            documentId = "1"; groupName = "radio1";
                            radios = @(
                                @{
                                    pageNumber = "1"; required = "false";
                                    value = "white"; xPosition = "142";
                                    yPosition = "384";
                                };
                                @{
                                    pageNumber = "1"; required = "false";
                                    value = "red"; xPosition = "74";
                                    yPosition = "384";
                                };
                                @{
                                    pageNumber = "1"; required = "false";
                                    value = "blue"; xPosition = "220";
                                    yPosition = "384";
                                };
                            );
                        };
                    );
                    signHereTabs   = @(
                        @{
                            documentId = "1"; pageNumber = "1";
                            xPosition = "191"; yPosition = "148";
                        };
                    );
                    textTabs       = @(
                        @{
                            documentId = "1"; font = "helvetica";
                            fontSize = "size14"; height = 23;
                            pageNumber = "1"; required = "false";
                            tabLabel = "text"; width = 84;
                            xPosition = "153"; yPosition = "230";
                        };
                    );
                    numericalTabs       = @(
                        @{
                            ValidationType = "Currency";
                            documentId = "1"; font = "helvetica";
                            fontSize = "size14"; height = 23;
                            pageNumber = "1"; required = "false";
                            tabLabel = "numericalCurrency"; width = 84;
                            xPosition = "153"; yPosition = "230";
                        };
                    );
                };
            };
        );
    };
    status                     = "created";
} | ConvertTo-Json -Depth 32 > $requestData
```

**`Python`**

```python title="Python"
def make_template_req(cls, args):
    """Creates template req object"""

    # document 1 (pdf)
    #
    # The template has two recipient roles.
    # recipient 1 - signer
    # recipient 2 - cc
    with open(args["doc_file"], "rb") as file:
        content_bytes = file.read()
    base64_file_content = base64.b64encode(content_bytes).decode("ascii")

    # Create the document model
    document = Document(  # create the DocuSign document object
        document_base64=base64_file_content,
        name="Lorem Ipsum",  # can be different from actual file name
        file_extension="pdf",  # many different document types are accepted
        document_id=1  # a label used to reference the doc
    )

    # Create the signer recipient model
    signer = Signer(role_name="signer", recipient_id="1", routing_order="1")
    # create a cc recipient to receive a copy of the envelope (transaction)
    cc = CarbonCopy(role_name="cc", recipient_id="2", routing_order="2")
    # Create fields using absolute positioning
    # Create a sign_here tab (field on the document)
    sign_here = SignHere(document_id="1", page_number="1", x_position="191", y_position="148")
    check1 = Checkbox(
        document_id="1",
        page_number="1",
        x_position="75",
        y_position="417",
        tab_label="ckAuthorization"
    )
    check2 = Checkbox(
        document_id="1",
        page_number="1",
        x_position="75",
        y_position="447",
        tab_label="ckAuthentication"
    )
    check3 = Checkbox(
        document_id="1",
        page_number="1",
        x_position="75",
        y_position="478",
        tab_label="ckAgreement"
    )
    check4 = Checkbox(
        document_id="1",
        page_number="1",
        x_position="75",
        y_position="508",
        tab_label="ckAcknowledgement"
    )
    list1 = List(
        document_id="1",
        page_number="1",
        x_position="142",
        y_position="291",
        font="helvetica",
        font_size="size14",
        tab_label="list",
        required="false",
        list_items=[
            ListItem(text="Red", value="red"),
            ListItem(text="Orange", value="orange"),
            ListItem(text="Yellow", value="yellow"),
            ListItem(text="Green", value="green"),
            ListItem(text="Blue", value="blue"),
            ListItem(text="Indigo", value="indigo"),
            ListItem(text="Violet", value="violet")
        ]
    )
    numerical = Numerical(
        document_id="1",
        validation_type="Currency",
        page_number="1",
        x_position="163",
        y_position="260",
        font="helvetica",
        font_size="size14",
        tab_label="numericalCurrency",
        width="84",
        height="23",
        required="false"
    )
    radio_group = RadioGroup(
        document_id="1",
        group_name="radio1",
        radios=[
            Radio(
                page_number="1", x_position="142", y_position="384",
                value="white", required="false"
            ),
            Radio(
                page_number="1", x_position="74", y_position="384",
                value="red", required="false"
            ),
            Radio(
                page_number="1", x_position="220", y_position="384",
                value="blue", required="false"
            )
        ]
    )
    text = Text(
        document_id="1",
        page_number="1",
        x_position="153",
        y_position="230",
        font="helvetica",
        font_size="size14",
        tab_label="text",
        height="23",
        width="84",
        required="false"
    )
    # Add the tabs model to the signer
    # The Tabs object wants arrays of the different field/tab types
    signer.tabs = Tabs(
        sign_here_tabs=[sign_here],
        checkbox_tabs=[check1, check2, check3, check4],
        list_tabs=[list1],
        numerical_tabs=[numerical],
        radio_group_tabs=[radio_group],
        text_tabs=[text]
    )

    # Top object:
    template_request = EnvelopeTemplate(
        documents=[document], email_subject="Please sign this document",
        recipients=Recipients(signers=[signer], carbon_copies=[cc]),
        description="Example template created via the API",
        name=args["template_name"],
        shared="false",
        status="created"
    )

    return template_request
```

**`Ruby`**

```ruby title="Ruby"
def make_template_req
  # document 1 is a PDF
  #
  # The template has two recipient roles.
  # recipient 1 - signer
  # recipient 2 - cc
  #
  # Read the PDF from the disk
  # Read files 2 and 3 from a local directory
  # The reads could raise an exception if the file is not available!
  template_name = args[:template_name]
  doc_file = 'World_Wide_Corp_fields.pdf'
  base64_file_content = Base64.encode64(File.binread(File.join('data', doc_file)))

  # Create the document model
  document = DocuSign_eSign::Document.new({
                                            # Create the Docusign document object
                                            'documentBase64' => base64_file_content,
                                            'name' => 'Lorem Ipsum', # Can be different from actual file name
                                            'fileExtension' => 'pdf', # Many different document types are accepted
                                            'documentId' => '1' # A label used to reference the doc
                                          })

  # Create the signer recipient model
  # Since these are role definitions, no name/email:
  signer = DocuSign_eSign::Signer.new({
                                        'roleName' => 'signer', 'recipientId' => '1', 'routingOrder' => '1'
                                      })
  # Create a cc recipient to receive a copy of the documents
  cc = DocuSign_eSign::CarbonCopy.new({
                                        'roleName' => 'cc', 'recipientId' => '2', 'routingOrder' => '2'
                                      })
  # Create fields using absolute positioning
  # Create a sign_here tab (field on the document)
  sign_here = DocuSign_eSign::SignHere.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '191', 'yPosition' => '148'
  )
  check1 = DocuSign_eSign::Checkbox.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '75', 'yPosition' => '417', 'tabLabel' => 'ckAuthorization'
  )
  check2 = DocuSign_eSign::Checkbox.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '75', 'yPosition' => '447', 'tabLabel' => 'ckAuthentication'
  )
  check3 = DocuSign_eSign::Checkbox.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '75', 'yPosition' => '478', 'tabLabel' => 'ckAgreement'
  )
  check4 = DocuSign_eSign::Checkbox.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '75', 'yPosition' => '508', 'tabLabel' => 'ckAcknowledgement'
  )

  list1 = DocuSign_eSign::List.new(
    'documentId' => '1',
    'pageNumber' => '1',
    'xPosition' => '142',
    'yPosition' => '291',
    'font' => 'helvetica',
    'fontSize' => 'size14',
    'tabLabel' => 'list',
    'required' => 'false',
    'listItems' => [
      DocuSign_eSign::ListItem.new('text' => 'Red', 'value' => 'red'),
      DocuSign_eSign::ListItem.new('text' => 'Orange', 'value' => 'orange'),
      DocuSign_eSign::ListItem.new('text' => 'Yellow', 'value' => 'yellow'),
      DocuSign_eSign::ListItem.new('text' => 'Green', 'value' => 'green'),
      DocuSign_eSign::ListItem.new('text' => 'Blue', 'value' => 'blue'),
      DocuSign_eSign::ListItem.new('text' => 'Indigo', 'value' => 'indigo'),
      DocuSign_eSign::ListItem.new('text' => 'Violet', 'value' => 'violet')
    ]
  )

  numerical = DocuSign_eSign::Numerical.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '163', 'yPosition' => '260',
    'font' => 'helvetica', 'fontSize' => 'size14', 'validationType' => 'Currency',
    'tabLabel' => 'numericalCurrency', 'width' => '84', 'required' => 'false'
  )
  radio_group =  DocuSign_eSign::RadioGroup.new(
    'documentId' => '1', 'groupName' => 'radio1',
    'radios' => [
      DocuSign_eSign::Radio.new('pageNumber' => '1', 'xPosition' => '142',
                                'yPosition' => '384', 'value' => 'white',
                                'required' => 'false'),
      DocuSign_eSign::Radio.new('pageNumber' => '1', 'xPosition' => '74',
                                'yPosition' => '384', 'value' => 'red',
                                'required' => 'false'),
      DocuSign_eSign::Radio.new('pageNumber' => '1', 'xPosition' => '220',
                                'yPosition' => '384', 'value' => 'blue',
                                'required' => 'false')
    ]
  )

  text = DocuSign_eSign::Text.new(
    'documentId' => '1', 'pageNumber' => '1',
    'xPosition' => '153', 'yPosition' => '230',
    'font' => 'helvetica', 'fontSize' => 'size14',
    'tabLabel' => 'text', 'height' => '23',
    'width' => '84', 'required' => 'false'
  )
  # Add the tabs model to the signer
  # The Tabs object takes arrays of the different field/tab types
  signer.tabs = DocuSign_eSign::Tabs.new(
    'signHereTabs' => [sign_here],
    'checkboxTabs' => [check1, check2, check3, check4],
    'listTabs' => [list1],
    'numericalTabs' => [numerical],
    'radioGroupTabs' => [radio_group],
    'textTabs' => [text]
  )
  # Create top two objects
  envelope_template_definition = DocuSign_eSign::EnvelopeTemplate.new(
    'description' => 'Example template created via the API',
    'shared' => 'false'
  )

  # Top object:
  DocuSign_eSign::EnvelopeTemplate.new(
    'documents' => [document],
    'name' => template_name,
    'emailSubject' => 'Please sign this document',
    'envelopeTemplateDefinition' => envelope_template_definition,
    'recipients' => DocuSign_eSign::Recipients.new(
      'signers' => [signer], 'carbonCopies' => [cc]
    ),
    'status' => 'created'
  )
end
```

## Step 3. Call the eSignature REST API

Make a POST request to [Templates:create](/docs/esign-rest-api/reference/templates/templates/create) to create the template. Here’s how you make the call, but make sure to substitute your API account ID for \{ACCOUNT_ID} and your template ID for \{TEMPLATE_ID}.

> **Note**
>
> View the source code for this how-to on GitHub: [Bash](https://github.com/docusign/code-examples-bash/blob/master/examples/eSignature/eg008CreateTemplate.sh), [C#](https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Examples/CreateNewTemplate.cs), [Java](https://github.com/docusign/code-examples-java/blob/master/src/main/java/com/docusign/controller/eSignature/services/CreateTemplateService.java), [Node.js](https://github.com/docusign/code-examples-node/blob/master/lib/eSignature/examples/createTemplate.js), [PHP](https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/eSignature/CreateTemplateService.php), [PowerShell](https://github.com/docusign/code-examples-powershell/blob/master/examples/eSignature/eg008CreateTemplate.ps1), [Python](https://github.com/docusign/code-examples-python/blob/master/app/eSignature/examples/eg008_create_template.py), or [Ruby](https://github.com/docusign/code-examples-ruby/blob/main/app/services/e_sign/eg008_create_template_service.rb).

**`Bash`**

```bash title="Bash"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     --header "Content-Type: application/json" \
     --data-binary @${request_data} \
     --request POST ${base_path}/v2.1/accounts/${account_id}/templates \
     --output $response
```

**`C#`**

```csharp title="C#"
var template = templatesApi.CreateTemplateWithHttpInfo(accountId, templateReqObject);
template.Headers.TryGetValue("X-RateLimit-Remaining", out remaining);
template.Headers.TryGetValue("X-RateLimit-Reset", out reset);

if (reset != null && remaining != null)
{
    DateTime resetDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(reset)).UtcDateTime;
    Console.WriteLine("API calls remaining: " + remaining);
    Console.WriteLine("Next Reset: " + resetDate);
}
```

**`Java`**

```java title="Java"
TemplateSummary template = CreateTemplateService.createTemplate(apiClient, accountId, CreateTemplateService.makeTemplate("Example Signer and CC template"));
```

**`Node.js`**

```javascript title="Node.js"
let templateReqObject = makeTemplate(args);
results = await templatesApi.createTemplate(args.accountId, {
  envelopeTemplate: templateReqObject,
}, (error, data, response) => {
  const headers = response?.headers;

  const remaining = headers?.['x-ratelimit-remaining'];
  const reset = headers?.['x-ratelimit-reset'];

  if (remaining && reset) {
    const resetInstant = new Date(Number(reset) * 1000);

    console.log(`API calls remaining: ${remaining}`);
    console.log(`Next Reset: ${resetInstant.toISOString()}`);
  }
  });
```

**`PHP`**

```php title="PHP"
$templatesListResponse = $templates_api->createTemplateWithHttpInfo($args['account_id'], $template_req_object);

$remaining = $templatesListResponse[2]['X-RateLimit-Remaining'] ?? null;
$reset = $templatesListResponse[2]['X-RateLimit-Reset'] ?? null;

if ($remaining !== null && $reset !== null) {
    $resetInstant = (new DateTime())->setTimestamp((int)$reset);
    error_log("API calls remaining: $remaining");
    error_log("Next Reset: " . $resetInstant->format(\DateTime::ATOM));
}
```

**`PowerShell`**

```text title="PowerShell"
Invoke-RestMethod `
    -Uri "${apiUri}/v2.1/accounts/${accountId}/templates" `
    -Method 'POST' `
    -Headers @{
    'Authorization' = "Bearer $accessToken";
    'Content-Type'  = "application/json";
} `
    -InFile (Resolve-Path $requestData).Path `
    -OutFile $response
```

**`Python`**

```python title="Python"
template_req_object = cls.make_template_req(args["template_args"])
(res, status, headers) = templates_api.create_template_with_http_info(account_id=args["account_id"], envelope_template=template_req_object)

remaining = headers.get("X-RateLimit-Remaining")
reset = headers.get("X-RateLimit-Reset")

if remaining is not None and reset is not None:
    reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
    print(f"API calls remaining: {remaining}")
    print(f"Next Reset: {reset_date}")
```

**`Ruby`**

```ruby title="Ruby"
template_req_object = make_template_req
result, _status, headers = templates_api.create_template_with_http_info(args[:account_id], template_req_object)

remaining = headers['X-RateLimit-Remaining']
reset = headers['X-RateLimit-Reset']

if remaining && reset
  reset_date = Time.at(reset.to_i).utc
  puts "API calls remaining: #{remaining}"
  puts "Next Reset: #{reset_date}"
end
```

## Expected response

"Example Signer and CC template" is created under **Templates** in the [Templates](https://apps-d.docusign.com/send/templates).

## Next steps

* Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects:    [Bash](https://github.com/docusign/code-examples-bash), [C#](https://github.com/docusign/code-examples-csharp), [Java](https://github.com/docusign/code-examples-java), [Node.js](https://github.com/docusign/code-examples-node), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).
* Learn about [templates](/docs/esign-rest-api/esign101/concepts/templates) or see [How to request a signature by email using a template](/docs/esign-rest-api/how-to/request-signature-template-remote).
* Learn about [composite templates](/docs/esign-rest-api/esign101/concepts/templates/composite) or see  [How to request a signature using a composite template](/docs/esign-rest-api/how-to/request-signature-composite-template-embedded).
* Review [Working with Templates](https://support.docusign.com/s/document-item?bundleId=xry1643227563338\&topicId=dqj1578456412286.html\&rsc_301).
* See how to [Go-Live](/docs/esign-rest-api/go-live) with a completed app and find the base path for API calls in the production environment.