> **Source:** https://knowledge.leegality.com/document-execution/api/sdks/events > **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 --- # Lifecycle Events The SDK delivers lifecycle events to your `onEvent` callback as `{ eventType, eventData }`. The SDK fires six events: `COMPLETED`, `SUBMISSION_PENDING`, `SUBMISSION_FAILED`, `ERROR`, `CANCELLED`, and `VALIDATION_FAILED`. ## Event envelope Every event arrives as: ```json { "eventType": "COMPLETED", "eventData": { ... } } ``` ## Common fields Five fields are present on **every** event, regardless of type: | Field | Type | Description | |---|---|---| | `journeyId` | string | Identifies this journey. May differ from the `journeyId` returned by `open()` — use `workflowRunContextId` for correlation instead. | | `workflowRunContextId` | string or `null` | The draft this event belongs to. `null` on events that fire before the session fully starts. | | `lastPage` | string or `null` | The step the sender was on — `"Create"`, `"Invitee"`, or `"Finalise"`. `null` if the journey had not rendered yet. | | `source` | string | Always `"leegality-sdk"`. | | `timestamp` | string | `dd-MM-yyyy HH:mm:ss`. | ### COMPLETED **Terminal.** The sender finished the journey and the pack was sent. ```json { "eventType": "COMPLETED", "eventData": { "journeyId": "mw3989mf-86d8158a22cb", "workflowRunContextId": "959a09e8-9ac9-4819-9e83-03d6dd0cca63", "lastPage": "Finalise", "source": "leegality-sdk", "timestamp": "05-11-2026 13:29:40" } } ``` **What to do:** Store `workflowRunContextId` — it is your reference for this pack. --- ### SUBMISSION_PENDING **Terminal.** The pack was submitted but processing is taking longer than the wait window (default 30 seconds). The popup closes and the final result arrives on your webhook, not through the SDK. ```json { "eventType": "SUBMISSION_PENDING", "eventData": { "journeyId": "mw3989mf-86d8158a22cb", "workflowRunContextId": "959a09e8-9ac9-4819-9e83-03d6dd0cca63", "lastPage": "Finalise", "source": "leegality-sdk", "timestamp": "05-11-2026 13:29:40" } } ``` **What to do:** Treat the pack as in-progress. Poll or wait for the webhook to confirm the outcome. --- ### SUBMISSION_FAILED The send was attempted and failed. The sender sees a **Retry Send** button and may retry — a `COMPLETED` can still arrive on the same journey. Check `errorCode` to determine whether the failure is recoverable or terminal. ```json { "eventType": "SUBMISSION_FAILED", "eventData": { "journeyId": "mw3989mf-86d8158a22cb", "workflowRunContextId": "959a09e8-9ac9-4819-9e83-03d6dd0cca63", "lastPage": "Finalise", "errors": [ { "errorCode": "submission_failed", "errorMessage": "" } ], "source": "leegality-sdk", "timestamp": "05-11-2026 13:29:40" } } ``` **What to do:** Log the error for support. The sender may retry and succeed, so do not close the pack off unless the `errorCode` indicates a terminal failure (e.g. `journey_token_invalidated`). --- ### ERROR **Terminal.** The journey could not start, or it broke mid-flight. This is unrelated to submission — it means the session itself failed. The `errorCode` is either the gateway's own code or one of these SDK-specific codes: | errorCode | When it fires | |---|---| | `boot_failed` | The boot call got no usable response. The journey never rendered. | | `handshake_failed` | The popup was not opened through the SDK (pasted URL, bookmark, forwarded link). | | `auth_failed` | The `auth: true` login returned with a state mismatch or missing code. | | `journey_token_invalidated` | A 401 during the journey with no specific error code from the server. | | `access_denied` | Sender cancelled the login flow. | | Gateway codes (e.g. `LE_ERR_SU_CMP_410`) | Server-side failures — expired link, pack already sent, etc. | Example (expired URL): ```json { "eventType": "ERROR", "eventData": { "journeyId": "mvz8f0vt-ef2086362d4e", "workflowRunContextId": null, "lastPage": null, "errors": [ { "errorCode": "LE_ERR_SU_CMP_410", "errorMessage": "Expired URL" } ], "source": "leegality-sdk", "timestamp": "02-11-2026 17:55:17" } } ``` **What to do:** Create a fresh draft for this sender. Errors before boot have no `workflowRunContextId` — use the one from your own Draft API response. --- ### CANCELLED **Terminal.** The sender closed the popup before an outcome was reported. ```json { "eventType": "CANCELLED", "eventData": { "journeyId": "mw39c0c6-1", "workflowRunContextId": null, "lastPage": null, "source": "leegality-sdk", "timestamp": "05-11-2026 13:32:19" } } ``` **What to do:** The sender abandoned the journey. You can re-open the same draft via the [re-issue endpoint](https://knowledge.leegality.com/document-execution/api/sdks/draft-api#re-issue-a-url) if the sender wants to resume. > **Note** > > `workflowRunContextId` and `lastPage` are best-effort on this event — they may be `null` if the popup closes before delivering them. Do not rely on `CANCELLED` for state; reconcile through the draft status via the [re-issue endpoint](https://knowledge.leegality.com/document-execution/api/sdks/draft-api#re-issue-a-url) instead. --- ### VALIDATION_FAILED **Not terminal — informational only.** The sender pressed Proceed with fields still invalid. They are still on the page fixing things. ```json { "eventType": "VALIDATION_FAILED", "eventData": { "journeyId": "mvz7zhjz-fe63e55298f4", "workflowRunContextId": "cf858f05-49a6-45f3-b12d-6a25e12ebe88", "lastPage": "Create", "errors": [ { "errorCode": "documents/0/irn", "errorMessage": "This is a required field" } ], "source": "leegality-sdk", "timestamp": "02-11-2026 17:43:18" } } ``` **What to do:** Nothing required. The `errorCode` on this event is the **field path**, not an error identifier — useful for analytics if you want to track which fields trip senders up. ## Event flow summary | Event | Terminal? | The sender... | Your app should... | |---|---|---|---| | `COMPLETED` | Yes | Finished and sent the pack | Store the reference ID | | `SUBMISSION_PENDING` | Yes | Submitted, but result is still processing | Wait for the webhook | | `SUBMISSION_FAILED` | Depends | Failed to send — may retry | Log the error, keep the pack open | | `ERROR` | Yes | Cannot continue this journey | Create a fresh draft | | `CANCELLED` | Yes | Closed the popup | Optionally re-engage via re-issue | | `VALIDATION_FAILED` | No | Is still fixing fields | No action needed |