> **Source:** https://knowledge.leegality.com/document-execution/api/sdks/draft-api > **Site:** Leegality Knowledge Base — https://knowledge.leegality.com > **About:** Leegality is a document execution platform covering eSigning, stamps, NeSL, workflows, and REST API integration. > **Navigation:** Every article on this site has a plain-text version at `.txt` (this format). To get an index of all articles with their `.txt` links, read: https://knowledge.leegality.com/llms.txt > **AI Guide:** For instructions on how to navigate this knowledge base as an AI agent, read: https://knowledge.leegality.com/ai-readable.txt --- # Draft API The Draft API creates a pack draft on your backend and returns a **signed launch URL** that the SDK opens in a popup. This endpoint requires the OAuth 2.0 access token obtained through the [v4 Authentication](https://knowledge.leegality.com/document-execution/api/v4-authentication) flow. Your access token stays on your server — the browser never sees it. ## Create a draft ### Request body ```json { "workflowId": "0499d58e-6336-420a-bc96-52ec5671aabb", "documents": [ { "uuid": "7a5450e1-7387-402e-828e-82c32614e147", "documentName": "Loan Agreement", "subDocuments": [ { "uuid": "5b121a81-4f18-4531-97b3-99f3668ba44d", "templateId": "a9f3ebfb-587f-4de7-b1cd-f0d91f23008f", "templateVersion": "1.0", "templateFieldValues": [ { "fieldId": "1793619830157", "fieldValue": "pre-filled value", "fieldName": "customerName" } ] } ] } ], "invitees": [ { "uuid": "6e18cb43-49d1-4f74-9c9f-d44fc4c324eb", "type": "signer", "level": 1, "inviteeDetails": [ { "uuid": "acec77dc-5c45-4b25-a2be-de0e18773657", "inviteeName": "Rajesh Kumar", "inviteeEmail": "rajesh@example.com" } ] } ], "journeyOptions": { "expiresIn": 60, "auth": false, "email": null, "successScreenAutoCloseMs": 3000, "okButtonLabel": "OK", "okButtonVisible": true } } ``` `documents` and `invitees` are optional — omit them to let the sender fill everything manually in the popup. | Field | Required | Description | |---|---|---| | `workflowId` | Yes | The full UUID of a **Published** v4 workflow. Get this from the workflow's detailed view in the Leegality dashboard. Draft or archived workflows are rejected. | | `documents` | No | Pre-fill document fields. Uses the same structure as the [Create Pack API](https://knowledge.leegality.com/document-execution/api/create-pack) — each document has `uuid`, `documentName`, and `subDocuments` containing `templateFieldValues` with `fieldId`, `fieldValue`, and `fieldName`. | | `invitees` | No | Pre-fill signer details. Uses the same structure as the Create Pack API — each invitee has `uuid`, `type`, `level`, and `inviteeDetails` containing `inviteeName`, `inviteeEmail`, etc. | | `journeyOptions` | No | Controls for the SDK popup window. Omit the entire block and every default applies. | ### journeyOptions These options travel inside the signed URL and cannot be tampered with on the client side. | Option | Type | Default | Description | |---|---|---|---| | `expiresIn` | number | Department default | Minutes until the launch URL expires. Range: **1–10080** (1 minute to 7 days). Values outside this range are rejected with 400. When omitted, the [department default](#department-level-settings) applies (60 minutes unless changed by an admin). After expiry, the popup shows an expired screen. | | `auth` | boolean | `false` | `false` — the signed URL is the credential and the journey opens immediately. `true` — the sender must log in inside the popup before the journey starts. See [Sender Login](https://knowledge.leegality.com/document-execution/api/sdks/authentication). | | `email` | string | `null` | The sender's email. **Required when `auth` is `true`** — the API rejects the request without it. Pre-filled on the login screen; the logged-in account must match it. | | `successScreenAutoCloseMs` | number | `3000` | How long the success screen shows before the popup closes itself, in milliseconds. Range: 0–60000. Set `0` to disable auto-close (the sender clicks the OK button instead). | | `okButtonLabel` | string | `"OK"` | Text on the success screen button. Maximum 32 characters, rendered as-is. | | `okButtonVisible` | boolean | `true` | Set `false` to hide the button and rely on auto-close alone. The combination `okButtonVisible: false` with `successScreenAutoCloseMs: 0` is rejected with 400 — the sender would have no way to exit the success screen. | ### Response ```json { "code": "SUCCESS", "message": "Draft created", "data": { "url": "https://workflow.leegality.com/workflow/embedded-run?exp=1789622610&credentialId=v1&signature=phiQV9QGmVlD...&d=eyJ3b3JrZm...", "workflowRunContextId": "f896e856-47df-4ef7-8d98-c261542b1a0d" } } ``` | Field | Description | |---|---| | `data.url` | The signed launch URL. Pass this to `LeegalitySenderSDK.open()` untouched. | | `data.workflowRunContextId` | Unique identifier for this draft. Use it to re-issue URLs or correlate with webhooks. | ### Error responses ```json { "code": "LE_ERR_DI_255", "traceId": null, "errors": [ { "message": "expiresIn must be between 1 and 10080 minutes", "path": "/api/v4/pack/draft", "code": "i18n.code.di.invitation.expiry.invalid" } ] } ``` | HTTP | Code | When | |---|---|---| | 400 | `LE_ERR_DI_255` | `expiresIn` is outside the 1–10080 range. | | 400 | `LE_ERR_DI_256` | `expiresIn` does not match the department's enforced default. Only returned when [Enforce link expiry](#department-level-settings) is ON. | | 400 | `LE_ERR_DI_257` | `okButtonVisible: false` with `successScreenAutoCloseMs: 0` — the sender would have no way to leave the success screen. | | 401 | — | Bearer token is missing, malformed, or expired. | ### The signed URL The URL contains four query parameters: `exp`, `credentialId`, `signature`, and `d`. Together they authenticate the request and carry your journey options to the popup. > **Danger — Do not modify the URL** > > The HMAC signature covers the query string byte-for-byte. Adding, removing, re-encoding, or reordering any parameter invalidates it. Treat the URL as one opaque string. ## Re-issue a URL If the launch URL expires or is lost, you can get a fresh one for the **same** draft. This mints a new URL with a new expiry and signature — the draft itself is unchanged. Journey options are passed as query parameters, not in a request body. `auth` is **required** — omitting it returns 400. ```bash curl "https://api-gateway.leegality.com/document-infrastructure/api/v4/pack/journey-url?workflowRunContextId=f896e856-47df-4ef7-8d98-c261542b1a0d&auth=false&expiresIn=60&successScreenAutoCloseMs=3000&okButtonLabel=OK&okButtonVisible=true" \ -H "Authorization: Bearer " ``` ### Response ```json { "code": "SUCCESS", "message": "Journey URL issued", "data": { "url": "https://workflow.leegality.com/workflow/embedded-run?exp=1790287814&..." } } ``` > **Warning — Journey options do not carry over from the create call** > > When you re-issue a URL, any option you omit falls back to the **department default** — not to what you sent when creating the draft. A draft created with `auth: true` and re-issued without it yields a URL that anyone holding it can open without logging in. > > Keep the options you sent alongside the `workflowRunContextId` in your own store, and repeat them on every re-issue. ### Error responses ```json { "code": "LE_ERR_DI_258", "traceId": null, "errors": [ { "message": "No draft found for workflowRunContextId 00000000-...", "path": "/api/v4/pack/journey-url", "code": "i18n.code.di.draft.not.found" } ] } ``` | HTTP | Code | When | |---|---|---| | 400 | `LE_ERR_DI_255` | `expiresIn` is outside the 1–10080 range, or `auth` is missing from the query string. | | 404 | `LE_ERR_DI_258` | The `workflowRunContextId` does not exist or belongs to a different user. | | 409 | `LE_ERR_DI_259` | The draft has already been submitted. You cannot re-issue a URL for a sent pack. | ## Save-as-Draft The SDK auto-saves the sender's progress each time they click Proceed to advance to the next page. If the sender closes the popup before submitting, you can re-open the same draft by calling the [re-issue endpoint](#re-issue-a-url) with the stored `workflowRunContextId` — the sender picks up where they left off. Auto-save is automatic and requires no action from your code. Each re-issued URL gets its own expiry — the original URL's expiry does not limit re-issue. > **Note** > > When the sender closes the popup, the SDK fires a [`CANCELLED`](https://knowledge.leegality.com/document-execution/api/sdks/events#cancelled) event. The `workflowRunContextId` and `lastPage` fields on this event are best-effort and may be `null` — use the `workflowRunContextId` from your original Draft API response to re-issue. ## Department-level settings Admins can configure URL lifetime defaults and enforcement per department in the Leegality dashboard under **Settings > Departments > Integration Configs**. | Setting | Default | Description | |---|---|---| | **Default journey URL lifetime** | 60 minutes | The `expiresIn` value used when your API call omits it. Range: 1–10080 minutes. | | **Enforce link expiry** | OFF | When ON, every draft must use the department default lifetime. Any `expiresIn` value that differs is rejected with 400 (`LE_ERR_DI_256`). | ### Behaviour when Enforce link expiry is ON | `expiresIn` in API call | Result | |---|---| | Omitted | Uses department default | | Matches department default | 201 — accepted | | Differs from department default | 400 — `LE_ERR_DI_256` "expiresIn does not match the department's enforced default" | ### Behaviour when Enforce link expiry is OFF | `expiresIn` in API call | Result | |---|---| | Omitted | Uses department default | | 1–10080 | Uses per-call value | | Outside 1–10080 | 400 — `LE_ERR_DI_255` | ## Environment hosts | Environment | Gateway host (Draft API) | |---|---| | Production | `https://gateway.leegality.com` | | Sandbox | `https://sandbox-gateway.leegality.com` | Use the gateway that matches the SDK script environment your page loads. See [SDK Reference](https://knowledge.leegality.com/document-execution/api/sdks/sdk-reference) for the script URLs.