# Create embedded template

The embedded template allows users to compose and create reusable templates on your website or mobile app using an iFrame, pop-up window, or a new tab. The process is similar to the embedded request, but it is used for template creation.

The templates created using the embedded template will be in the `draft` state until the user completes the create process from the generated URL.

## Create an embedded template link

{% post /%}
{% path text="/v1/template/createEmbeddedTemplateUrl" /%}

The embedded template link is created in the same way as the regular template, but with additional properties to customize the embedded process. Please refer to the {% customlink href="/template/create-template/" text="Create template" /%} for the create template API specific properties.

This API supports both `multipart/form-data` and `application/json` content types.

### Asynchronous document processing

The template creation process is asynchronous in nature. You will receive an embedded request URL and template ID immediately, but the uploaded document might still be processing in the background. In the meantime, you can see the progress of the document processing by opening the embedded create template URL in the browser.

### Example request using multipart/form-data

{% codetab id="codetab1" %}

cURL

```shell
curl --location --request POST 'https://api.boldsign.com/v1/template/createEmbeddedTemplateUrl' \
     --header 'X-API-KEY: ****YOUR-API-KEY****' \
     --form 'Title=" API template"' \
     --form 'Description=" API template description"' \
     --form 'DocumentTitle=" API document title"' \
     --form 'DocumentMessage=" API document message description"' \
     --form 'AllowMessageEditing=" true"' \
     --form 'Roles[0][name]="Manager"' \
     --form 'Roles[0][index]="1"' \
     --form 'ShowToolbar="true"' \
     --form 'ShowSaveButton="true"' \
     --form 'ShowSendButton="true"' \
     --form 'ShowPreviewButton="true"' \
     --form 'ShowNavigationButtons="true"' \
     --form 'ShowTooltip="false"' \
     --form 'ViewOption="PreparePage"' \
     --form 'AllowNewFiles="true"' \
     --form 'AllowModifyFiles="true"' \
     --form 'Files=@"/docs/test-document.pdf"'
```

C#

```csharp
var apiClient = new ApiClient("https://api.boldsign.com", "Your_API_Key");

var templateClient = new TemplateClient(apiClient);

var templateRequest = new CreateEmbeddedTemplateRequest
{
    Title = "Template created from API SDK",
    DocumentTitle = "API document title",
    Roles = 
    [
        new TemplateRole()
        {
            Index = 1,
            Name = "Manager"
        }
    ],
    Files = new List<IDocumentFile>
    {
        new DocumentFilePath
        {
            ContentType = "application/pdf",
            FilePath = "YOUR_FILE_PATH",
        },
    },
    ViewOption = PageViewOption.PreparePage,
    ShowToolbar = true,
};

var templateCreated = templateClient.CreateEmbeddedTemplateUrl(templateRequest);
var templateCreateUrl = templateCreated.CreateUrl;
```

Python

```python
import boldsign

configuration = boldsign.Configuration(host = "https://api.boldsign.com", api_key="Your-API-KEY")

with boldsign.ApiClient(configuration) as api_client:
    
    template_api = boldsign.TemplateApi(api_client)
	
    template_role = boldsign.TemplateRole(
        index=1,
        name="Manager")
    
    embedded_create_template_request = boldsign.EmbeddedCreateTemplateRequest (
        title="API template",
        documentTitle="API document title", 
        roles=[template_role],        
        showToolbar=True,
        viewOption="FillingPage",
        files=["YOUR_FILE_PATH"])
    
    template_created = template_api.create_embedded_template_url(embedded_create_template_request)
```

PHP

```php
<?php require_once "vendor/autoload.php";

use BoldSign\Configuration;
use BoldSign\Api\TemplateApi;
use BoldSign\Model\{TemplateRole, EmbeddedCreateTemplateRequest, FileInfo};

$config = new Configuration();
$config->setHost('https://api.boldsign.com');
$config->setApiKey('YOUR_API_KEY');

$template_api = new TemplateApi($config);

$role = new TemplateRole();
$role->setIndex(1);
$role->setName('Manager');

$embedded_create_template_request = new EmbeddedCreateTemplateRequest();
$embedded_create_template_request->setTitle('API template');
$embedded_create_template_request->setDocumentTitle('API document title');
$embedded_create_template_request->setRoles([$role]);
$embedded_create_template_request->setShowToolbar(true);
$embedded_create_template_request->setViewOption('PreparePage');
$files = new FileInfo();
$files = 'YOUR_FILE_PATH';
$embedded_create_template_request->setFiles([$files]);

$template_created = $template_api->createEmbeddedTemplateUrl($embedded_create_template_request);
```

Java

```java
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("https://api.boldsign.com");
client.setApiKey("YOUR_API_KEY");
           
TemplateApi templateApi = new TemplateApi(client);

TemplateRole role = new TemplateRole();
role.setIndex(1);
role.setName("Manager");

EmbeddedCreateTemplateRequest embeddedCreateTemplateRequest = new EmbeddedCreateTemplateRequest();
embeddedCreateTemplateRequest.setTitle("API template");
embeddedCreateTemplateRequest.setDocumentTitle("API document title");
embeddedCreateTemplateRequest.setRoles(Arrays.asList(role));
embeddedCreateTemplateRequest.setShowToolbar(true);
embeddedCreateTemplateRequest.setViewOption(EmbeddedCreateTemplateRequest.ViewOptionEnum.PREPARE_PAGE);
File file = new File("YOUR_FILE_PATH");
embeddedCreateTemplateRequest.setFiles(Arrays.asList(file));

EmbeddedTemplateCreated templateCreated = templateApi.createEmbeddedTemplateUrl(embeddedCreateTemplateRequest);
```

NodeJS

```js
import { TemplateApi, TemplateRole, EmbeddedCreateTemplateRequest } from "boldsign";
import * as fs from 'fs';

const templateApi = new TemplateApi("https://api.boldsign.com");
templateApi.setApiKey("YOUR_API_KEY");

const role = new TemplateRole();
role.index = 1;
role.name = "Manager";

const files = fs.createReadStream("YOUR_FILE_PATH"); 

const embeddedCreateTemplateRequest = new EmbeddedCreateTemplateRequest();
embeddedCreateTemplateRequest.title = "Testing Embedded Template";
embeddedCreateTemplateRequest.documentTitle = "Embedded Template Test";
embeddedCreateTemplateRequest.showToolbar = true;
embeddedCreateTemplateRequest.viewOption = EmbeddedCreateTemplateRequest.ViewOptionEnum.PreparePage;
embeddedCreateTemplateRequest.roles = [role];
embeddedCreateTemplateRequest.files = [files];

const templateCreated = templateApi.createEmbeddedTemplateUrl(embeddedCreateTemplateRequest);
```

{% /codetab %}

### Code snippet using application/json

{% codetab id="codetab2" %}

cURL
```shell 
curl -X POST 'https://api.boldsign.com/v1/template/createEmbeddedTemplateUrl' \
    -H 'X-API-KEY: ****YOUR-API-KEY****' \
    -H 'Content-Type: application/json' \
    -d '{
        "Title": "API template",
        "Description": "API template description",
        "DocumentTitle": "API document title",
        "DocumentMessage": "API document message description",
        "AllowMessageEditing": true,
        "Roles": [
            {
                "Name": "Manager",
                "Index": 1
            }
        ],
        "ShowToolbar": true,
        "ShowSaveButton": true,
        "ShowSendButton": true,
        "ShowPreviewButton": true,
        "ShowNavigationButtons": true,
        "ShowTooltip": false,
        "ViewOption": "PreparePage",
        "Files": [
            "data:application/pdf;base64,JVBERi0xLjcKJcfs..."
        ]
    }'
```

{% /codetab %}

### Request body

{% nestedtable %}

- {% arguments name="RedirectUrl" /%}{% batch datatype="string" /%}
- The redirect URI to be redirected after the template create process is completed. The string should be in URI format.

---

- {% arguments name="ShowToolbar" /%}{% batch datatype="boolean" /%}
- Controls the visibility of the toolbar at the top of the document editor.

  Defaults to false.

---

- {% arguments name="ViewOption" /%}{% batch datatype="string" /%}
- Configures the initial view page to be loaded from the generated URL. The FillingPage is used to customize roles, enforce authentication, etc. The PreparePage is used to configure form fields for the roles.

  Either PreparePage or FillingPage.

  Defaults to PreparePage.

---

- {% arguments name="ShowSaveButton" /%}{% batch datatype="boolean" /%}
- Controls the visibility of the `Save and Close` button from the `More Action` drop down menu. Set to false if you don't want your users to save the template as a draft instead of finalizing the template.

  Defaults to true.

---

- {% arguments name="ShowSendButton" /%}{% batch datatype="boolean" /%}
- Controls the visibility of the `Create template` button at the top right corner of the page. Set to false if you want your users to save the template as only drafts instead of finalizing the template.

  Defaults to true.

---

- {% arguments name="ShowPreviewButton" /%}{% batch datatype="boolean" /%}
- Controls the visibility of the `Preview` button from the `More Action` drop down menu. Set to false if you don't want your users to preview the template before finalizing it.

  Defaults to true.

---

- {% arguments name="AllowNewFiles" /%}{% batch datatype="boolean" /%}
-  When set to true, the sender can add new files while using this template to send signature requests. If set to false, the sender will not be able to add new files.

    Defaults to true.

---

- {% arguments name="AllowModifyFiles" /%}{% batch datatype="boolean" /%}
-  When set to true, the sender can replace or delete existing files while using this template to send signature requests. If set to false, the sender will not have the ability to replace or delete files.

    Defaults to true.

---

- {% arguments name="ShowNavigationButtons" /%}{% batch datatype="boolean" /%}
- Controls the visibility of the `Back` button. Set to false if you don't want your users to navigate away from the current page.

  Defaults to true.

---

- {% arguments name="LinkValidTill" /%}{% batch datatype="string" /%}
- Configures the expiration for the generated URL. A maximum of 180 days can be assigned. The string should be in date-time format.

---

- {% arguments name="ShowTooltip" /%}{% batch datatype="boolean" /%}
- To control the visibility of the `Tooltip` near the assignee field on the prepare page, set it to "true" if you want to show the tooltip to the user.

  Defaults to false.

---

- {% arguments name="AutoDetectFields" /%}{% batch datatype="boolean" /%}
- When enabled, it will convert all the fillable form fields in the document to BoldSign form fields. BoldSign supports Textbox, Checkbox, Radio button, and Signature form fields. Other fields will not be detected as of now.

  Defaults to false.

{% /nestedtable %}

### Example response

```json
{
    "templateId": "6a154b94...",
    "createUrl": "https://app.boldsign.com/document/embed/?templateId=6a154b94..."
}
```
