# API Integration Guide
> Guide to implement an electronic signature flow using the Legaldoc.io API and the embedded widget.
Guide to implement an electronic signature flow using the Legaldoc.io API and the embedded widget.
---
## Prerequisites
- **API Key**: Authentication token for the API
- **Configured Template**: A template created in the Legaldoc.io portal
### Authentication
All requests must include:
```http
Authorization: {API_KEY}
Content-Type: application/json
```
---
## Integration Flow
---
## Step 1: Get the Template ID
The ID is obtained from the URL when editing a template:
```
https://app.legaldoc.io/t/my-team/templates/18
↑
Template ID = 18
```
### Email Options Configuration
If you **do not want** automatic emails to be sent to signers, you must configure the **Email Options** in the template editor:
1. In the template editor, under **General**
2. In the **Email Options** section, uncheck all email sending checkboxes:
- ❌ Send recipient completed signature email
- ❌ Send recipient signature request email
- ❌ Send recipient deleted email
- ❌ Send document pending email
- ❌ Send document completed email
- ❌ Send document deleted email
- ❌ Send document completed email to owner
> **Note:** With these options disabled, you must manually distribute the signing links using the API or the embedded widget.
---
## Step 2: Get Template Details
Get the signer ID configured in the template.
### Request
```http
GET https://app.legaldoc.io/api/v1/templates/18
```
### Response (simplified)
```json
{
"id": 18,
"title": "My Contract.pdf",
"recipients": [
{
"id": 52,
"name": "Recipient",
"email": "recipient@legaldoc.io",
"role": "SIGNER"
}
]
}
```
> **Important:** Save the `recipients[].id` (in this example: **52**) for the next step.
---
## Step 3: Generate the Document
Create a document from the template with the actual signer data.
### Request
```http
POST https://app.legaldoc.io/api/v1/templates/18/generate-document
```
### Body
```json
{
"title": "Contract - Client ABC",
"recipients": [
{
"id": 52,
"name": "John Doe",
"email": "john.doe@company.com"
}
]
}
```
### Response
```json
{
"documentId": 153,
"recipients": [
{
"recipientId": 174,
"name": "John Doe",
"email": "john.doe@company.com",
"token": "abc123XYZ",
"role": "SIGNER",
"signingUrl": "https://app.legaldoc.io/sign/abc123XYZ"
}
]
}
```
> **Important:** Save the `token` (**abc123XYZ**) for use in the embedded widget.
### 3.1 Pre-fill Document Fields (Optional)
If you need certain fields to appear with default values, you can use `prefillFields`.
**Example:** Pre-fill a text field with a bank account number.
#### Prerequisite: Identify the field
From the response in **Step 2** (Get Template Details), find the field you want to pre-fill in the `fields` array:
```json
{
"id": 526,
"type": "TEXT",
"recipientId": 144,
"fieldMeta": {
"label": "Account Number",
"type": "text",
"required": true
}
}
```
> **Note:** Save the field `id` (in this example: **526**).
#### Request with pre-filled fields
```http
POST https://app.legaldoc.io/api/v1/templates/19/generate-document
```
```json
{
"title": "Commercial Contract",
"recipients": [
{
"id": 144,
"name": "John Doe",
"email": "john.doe@company.com"
}
],
"prefillFields": [
{
"id": 526,
"type": "text",
"label": "Account Number",
"value": "12323123"
}
]
}
```
The generated document will have the "Account Number" field already completed with the value `12323123`.
#### Make the field read-only
If you want the signer **not to be able to modify** the pre-filled value:
1. In the template editor at app.legaldoc.io, select the field, go to **advanced settings**
2. Enable the **"Read only"** option in the field properties
3. Save the template
This way, the field will appear pre-filled and locked for editing.
---
## Step 4: Send the Document
Activate the document for signing.
### Request
```http
POST https://app.legaldoc.io/api/v1/documents/153/send
```
### Response
```json
{
"message": "Document sent for signing successfully",
"id": 153,
"status": "PENDING",
"recipients": [
{
"id": 174,
"name": "John Doe",
"email": "john.doe@company.com",
"token": "abc123XYZ",
"signingUrl": "https://app.legaldoc.io/sign/abc123XYZ"
}
]
}
```
---
## Step 5: Embedded Widget
### 5.1 Include the Script
```html
```
### 5.2 Add the Component
```html