> **Source:** https://knowledge.leegality.com/document-execution/api/sdks/quick-start > **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 --- # Quick Start A minimal integration in four steps. By the end your page opens a Leegality sending journey in a popup and receives lifecycle events back. ## Step 1 — Create a pack draft (backend) Your server calls the Draft API with your org API token. The response includes a **signed launch URL** — the only thing your frontend needs. ```bash curl -X POST https://gateway.leegality.com/document-infrastructure/api/v4/pack/draft \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "workflowId": "" }' ``` Response: ```json { "code": "SUCCESS", "message": "Draft created", "data": { "url": "https://workflow.leegality.com/workflow/embedded-run?exp=...&credentialId=...&signature=...&d=...", "workflowRunContextId": "f896e856-47df-4ef7-8d98-c261542b1a0d" } } ``` Pass `data.url` to your frontend as-is. > **Danger — Do not modify the URL** > > The signature covers the query string byte-for-byte. Adding, removing, or re-encoding any parameter breaks it. ## Step 2 — Load the SDK script (frontend) Add a single ` ``` This defines one global: `LeegalitySenderSDK`, with one method: `open()`. ## Step 3 — Open the journey on a click Call `open()` inside a button's click handler. Pass the launch URL and a callback. ```js const sendBtn = document.getElementById('send-btn'); let launchUrl = null; // Fetch the URL BEFORE the click (see note below) async function prepare() { const res = await fetch('/api/leegality/draft', { method: 'POST' }); const json = await res.json(); launchUrl = json.url; sendBtn.disabled = false; } prepare(); // Open on click — no await between the click and open() sendBtn.addEventListener('click', () => { const session = LeegalitySenderSDK.open({ url: launchUrl, onEvent: handleEvent, }); }); ``` > **Warning — Call open() synchronously inside the click handler** > > Browsers block popups that cannot be traced back to a user action. An `await` between the click and the `open()` call breaks that trace. Fetch the launch URL before the click, then call `open()` directly inside the handler. ## Step 4 — Handle events Your `onEvent` callback receives `{ eventType, eventData }` for every lifecycle event. The `eventType` alone tells you whether the journey is over. ```js function handleEvent({ eventType, eventData }) { switch (eventType) { case 'COMPLETED': // Terminal. The pack was sent successfully. console.log('Sent:', eventData.workflowRunContextId); break; case 'SUBMISSION_PENDING': // Terminal. Submitted but still processing — wait for your webhook. console.log('Processing:', eventData.workflowRunContextId); break; case 'SUBMISSION_FAILED': // May be recoverable OR terminal — check the errorCode. // Recoverable: sender can retry in the popup (do not close the pack). // Terminal (e.g. journey_token_invalidated, auth_lockout): // the journey is over — create a fresh draft. console.log('Failed:', eventData.errors[0].errorCode); break; } } ``` ## Complete example One self-contained HTML file. **Serve it over HTTP** (e.g. `python3 -m http.server 8080`) and open it at `http://localhost:8080` — do not open it as a `file://` URL. The SDK uses `postMessage` to communicate between your page and the popup, which requires proper HTTP origins. Save it, serve it, and click the button. ```html Leegality Sender SDK — minimal integration


  
  

  


```

## Next steps

- [Draft API](https://knowledge.leegality.com/document-execution/api/sdks/draft-api) — journeyOptions, re-issuing URLs, and the full request/response reference
- [SDK Reference](https://knowledge.leegality.com/document-execution/api/sdks/sdk-reference) — the `open()` method in detail, return value, and popup behaviour
- [Lifecycle Events](https://knowledge.leegality.com/document-execution/api/sdks/events) — the three lifecycle events with exact payloads