Developers · v1.0.0

Partner API.

Opret dokumenter fra versionerede skabeloner, send dem til underskrift via e-mail eller indlejret i din egen app, modtag signerede webhooks, og håndter GDPR-eksport og -sletning pr. slutkunde.

LegalDock leverer dokumentskabeloner, ikke individuel juridisk rådgivning. Som partner skal du vise denne oplysning til dine slutbrugere.

Referencen nedenfor er på engelsk, så den matcher OpenAPI-specifikationen.

Quickstart

Create a test key in the partner portal, create a document, then send it. In the test environment no email is sent; the send response contains signing links you can open directly.

curl -X POST 'https://legaldock.dk/api/v1/documents' \
  -H 'Authorization: Bearer ldk_test_...' \
  -H 'Idempotency-Key: deal_4821-create' \
  -H 'Content-Type: application/json' \
  -d '{
  "template_slug": "consulting-agreement-dk",
  "locale": "da",
  "title": "Konsulentaftale: Nordlys ApS",
  "data": {
    "client_name": "Nordlys ApS",
    "consultant_name": "Anna Hansen",
    "start_date": "2026-12-01"
  },
  "signers": [
    {
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "role": "Konsulent"
    },
    {
      "name": "Peter Sørensen",
      "email": "peter@nordlys.dk",
      "role": "Kunde"
    }
  ],
  "signing_order": "sequential",
  "delivery_mode": "email",
  "external_id": "deal_4821",
  "external_customer_id": "cust_1093",
  "metadata": {
    "crm_owner": "team-north"
  }
}'
curl -X POST 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../send' \
  -H 'Authorization: Bearer ldk_test_...'

Hosted data collection

Don't have all the field values? Create the document with "data_collection": {} (optionally with the values you already know in data) and forward the returned data_collection.url to whoever has the information: the signer, an HR admin, anyone. They fill in a LegalDock-hosted form built from the template's fields, with your branding and a small LegalDock mark.

  • Values you send in data are shown read-only and cannot be changed by the person filling in.
  • The link is single-use, expires after 7 days by default (1-30 with expires_in_days), only works for that one document in its own environment, and is returned once: we store only a hash. Lost it? Call POST /documents/{id}/data-collection for a new one (the old one stops working).
  • Submissions are validated with the same field rules as PATCH and /send, so a submitted document is ready to send. While the link is pending, data changes, send and finalise return 409 DATA_COLLECTION_PENDING.
  • On submission we emit document.data_submitted. The document stays a draft; you decide when to call /send (which is when embedded signing links are returned and a credit is used).
  • Test-environment fill-in pages show a TEST banner, like test signing pages.
curl -X POST 'https://legaldock.dk/api/v1/documents' \
  -H 'Authorization: Bearer ldk_test_...' -H 'Content-Type: application/json' \
  -d '{"template_slug":"consulting-agreement-dk","title":"Konsulentaftale",
       "data":{"client_name":"Nordlys ApS"},
       "signers":[{"name":"Anna Hansen","email":"anna@example.dk"}],
       "data_collection":{"expires_in_days":7}}'

Authentication

Send your key as Authorization: Bearer ldk_live_… or x-api-key: ldk_live_…. Keys look like ldk_test_<secret> or ldk_live_<secret>, are shown once at creation, and are stored only as a SHA-256 hash. Keys can expire and can be revoked at any time in the partner portal. Keep them on your server; never ship them to a browser or mobile app.

ScopeGrants
templates:readList and read templates.
documents:readList and read documents, audit trails and signed PDFs.
documents:writeCreate, update, send, cancel and remind; receive signing links.
webhooks:manageReserved for webhook endpoint management (managed in the partner portal today).
customers:manageExport and erase all data for one external_customer_id.

Test & live environments

Every key belongs to one environment. A test key can only see and change test documents, a live key only live documents; requests for a document in the other environment return 404.

  • Test documents never send email: no invitations, reminders or completion emails, in either delivery mode.
  • Sending a test document returns sandbox: true and signing_links so you can complete the signing flow yourself.
  • Test signing pages show a “TEST / SANDBOX” banner. Test signatures have no legal effect.
  • Completed test documents and their PDFs carry a fixed “TEST — No legal effect” watermark (Danish: “TEST — Ingen retsvirkning”). It is added on our side when the document is sealed and cannot be turned off.
  • Test usage is recorded for visibility but never billed.
  • Test volume is capped on purpose: 100 test documents per partner per calendar month (UTC), across all your test keys. That is plenty for building and running an integration, but test keys are not meant for production traffic. Documents count when created and deleting them does not give the allowance back. Beyond the cap, POST /documents returns 429 TEST_DOCUMENT_LIMIT_REACHED with a Retry-After header pointing to the 1st of next month. Need more for a load test? Contact us.
  • Webhook payloads carry environment and livemode (covered by the signature), plus a LegalDock-Environment header.

Prepaid document credits

Live documents are prepaid. Your plan is invoiced at the start of each monthly billing period; when the invoice is paid, the plan's included documents are added as credits valid until the end of that period. Each live document uses one credit when it is sent for signing (or finalised), and a document is never charged twice.

  • With no credits left, POST /documents/{id}/send returns 402 INSUFFICIENT_CREDITS and nothing is sent. Drafts can still be created and edited.
  • Extra documents can be bought in advance in the partner portal at your plan's per-document rate. They are added once the invoice is paid and do not expire.
  • Unused monthly credits expire at the end of their billing period.

Errors

Every error uses the same envelope. Messages are safe to log and never include internal details; quote the reference when contacting support.

{
  "error": {
    "code": "DOCUMENT_NOT_FOUND",
    "message": "Document not found"
  },
  "reference": "k3J9xQ2a"
}
HTTPcodeMeaning
400INVALID_JSONBody is not valid JSON.
400VALIDATION_ERRORBody, path or query failed schema validation.
400INVALID_CURSORThe pagination cursor is malformed.
400INVALID_IDEMPOTENCY_KEYIdempotency-Key is not 1-128 of A-Z a-z 0-9 . _ : -
401UNAUTHORIZEDMissing, malformed, unknown, revoked or expired key.
403FORBIDDENKey lacks the required scope, or the partner is not active.
402INSUFFICIENT_CREDITSNo prepaid document credits left (live, or test when billing is rehearsed with a test plan). Credits arrive when the monthly plan invoice is paid; extra documents can be bought in the partner portal.
404DOCUMENT_NOT_FOUNDNo such document for this partner and environment.
404TEMPLATE_NOT_FOUNDUnknown or inactive template, or unknown version.
409DOCUMENT_NOT_DRAFTThe document can only be changed while it is a draft.
409INVALID_DOCUMENT_STATEOperation not allowed in the document's current state.
409DATA_COLLECTION_PENDINGA hosted fill-in link is pending: data cannot be changed and the document cannot be sent or finalised until document.data_submitted, or until you revoke the link.
409PDF_NOT_READYPDF exists only once the document is completed.
409IDEMPOTENCY_KEY_REUSEDSame Idempotency-Key was used with a different body.
409IDEMPOTENCY_IN_PROGRESSThe original request with this key is still running.
410PERSONAL_DATA_ERASEDThe document's personal data was erased on request.
413PAYLOAD_TOO_LARGERequest body exceeds 100 KB.
422FIELD_VALIDATIONDocument data violates the template's field rules.
429RATE_LIMITEDRate limit exceeded; wait for Retry-After seconds.
429TEST_DOCUMENT_LIMIT_REACHEDMonthly test allowance (100 test documents per partner) is used up; Retry-After points to the 1st of next month (UTC). Use a live key for production.
500INTERNAL_ERRORUnexpected error. Quote the reference to support.

Rate limits

Exceeding a limit returns 429 RATE_LIMITED with a Retry-After header in seconds. No other rate-limit headers are sent. The monthly test-document allowance returns 429 TEST_DOCUMENT_LIMIT_REACHED instead.

Applies toLimitRetry-After
Every request, per API key2,000 / minute60
Missing, malformed, unknown, revoked or expired key, per IP30 / 10 minutes600
POST /documents, per partner (test + live combined)40 / hour60
POST /documents with a test key, per partner (test documents created, all test keys combined)100 / calendar month (UTC)until the 1st
POST /documents/{id}/send, per partner20 / hour60
POST /documents/{id}/data-collection, per partner120 / hour60
Hosted fill-in page: opening, per IP / submitting, per IP60 / 10 minutes; 20 / hour—
Reminders, per signer3 / 24 hours60
Reminders, per partner30 / hour60
GET /customers/{id}/export, per partner120 / hour3600
DELETE /customers/{id}, per partner60 / hour3600

Idempotency

1-128 characters of A-Z a-z 0-9 . _ : - . Retrying with the same key and same body within 24 hours replays the first successful response. A different body returns 409 IDEMPOTENCY_KEY_REUSED; a concurrent duplicate returns 409 IDEMPOTENCY_IN_PROGRESS. Failed requests are not stored.

Supported on POST /documents. Replayed responses include Idempotency-Replayed: true.

Pagination

List and export endpoints return next_cursor. Pass it back as ?cursor= until it is null. GET /documents takes limit 1–100 (default 25); the customer export takes 1–50 (default 25).

Endpoints

Base URL https://legaldock.dk/api/v1. Request bodies are JSON, at most 100 KB, and unknown properties are rejected.

Templates

get/templatestemplates:read

List templates

All active templates with their current version id.

curl -X GET 'https://legaldock.dk/api/v1/templates' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "templates": [
    {
      "slug": "consulting-agreement-dk",
      "name": "Konsulentaftale",
      "name_da": "Konsulentaftale",
      "name_en": "Consulting agreement",
      "locale": "da",
      "available_locales": [
        "da",
        "en"
      ],
      "version": 3,
      "current_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"
    }
  ],
  "count": 1
}
get/templates/{slug}templates:read

Get a template

One active template with its current version and field definitions.

  • slug (path, required)
curl -X GET 'https://legaldock.dk/api/v1/templates/consulting-agreement-dk' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "template": {
    "slug": "consulting-agreement-dk",
    "name": "Konsulentaftale",
    "name_da": "Konsulentaftale",
    "name_en": "Consulting agreement",
    "description_da": "Aftale mellem virksomhed og selvstændig konsulent.",
    "description_en": "Agreement between a company and an independent consultant.",
    "locale": "da",
    "available_locales": [
      "da",
      "en"
    ],
    "estimated_minutes": 10,
    "signing_enabled": true,
    "current_version": {
      "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
      "version": 3,
      "created_at": "2026-10-01T09:00:00.000Z"
    },
    "fields": [
      {
        "key": "client_name",
        "type": "text",
        "label_da": "Kundens navn",
        "label_en": "Client name",
        "options": null,
        "default_value": null,
        "required": true,
        "depends_on": null,
        "min_value": null,
        "max_value": null,
        "max_field": null
      }
    ]
  }
}

Documents

get/documentsdocuments:read

List documents

Newest-updated first, cursor paginated. Only documents in the key's environment.

  • limit (query)
  • cursor (query) — next_cursor from the previous page.
  • external_id (query) — Exact match filter.
curl -X GET 'https://legaldock.dk/api/v1/documents' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "items": [
    {
      "id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
      "title": "Konsulentaftale: Nordlys ApS",
      "status": "draft",
      "template_slug": "consulting-agreement-dk",
      "template_id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
      "template_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
      "locale": "da",
      "external_id": "deal_4821",
      "external_customer_id": "cust_1093",
      "metadata": {
        "crm_owner": "team-north"
      },
      "environment": "test",
      "signing_order": "sequential",
      "created_at": "2026-11-15T10:00:00.000Z",
      "updated_at": "2026-11-15T10:00:00.000Z",
      "completed_at": null,
      "sent_for_signing_at": null,
      "cancelled_at": null
    }
  ],
  "next_cursor": null
}
post/documentsdocuments:write

Create a document

Creates a draft in the key's environment from the template's current (or pinned) version. delivery_mode and redirect_url are fixed at creation. Supports the Idempotency-Key header; successful responses are stored for 24 hours. Pass data_collection to also get a hosted fill-in link (data_collection.url) for whoever has the information: values you send in data are pre-filled and locked, the rest is collected on a LegalDock page and validated with the same field rules as this API. The link is returned only in this response (an idempotent replay returns url: null; issue a new one with POST /documents/{id}/data-collection). Test keys may create at most 100 test documents per partner per calendar month (UTC, counted at creation, not refunded by deletion); beyond that the call returns 429 TEST_DOCUMENT_LIMIT_REACHED.

  • Idempotency-Key (header)
curl -X POST 'https://legaldock.dk/api/v1/documents' \
  -H 'Authorization: Bearer ldk_test_...' \
  -H 'Idempotency-Key: deal_4821-create' \
  -H 'Content-Type: application/json' \
  -d '{
  "template_slug": "consulting-agreement-dk",
  "locale": "da",
  "title": "Konsulentaftale: Nordlys ApS",
  "data": {
    "client_name": "Nordlys ApS",
    "consultant_name": "Anna Hansen",
    "start_date": "2026-12-01"
  },
  "signers": [
    {
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "role": "Konsulent"
    },
    {
      "name": "Peter Sørensen",
      "email": "peter@nordlys.dk",
      "role": "Kunde"
    }
  ],
  "signing_order": "sequential",
  "delivery_mode": "email",
  "external_id": "deal_4821",
  "external_customer_id": "cust_1093",
  "metadata": {
    "crm_owner": "team-north"
  }
}'

Response 201

{
  "document": {
    "id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
    "template_id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "template_slug": "consulting-agreement-dk",
    "template_version": 3,
    "template_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
    "locale": "da",
    "title": "Konsulentaftale: Nordlys ApS",
    "data": {
      "client_name": "Nordlys ApS",
      "consultant_name": "Anna Hansen",
      "start_date": "2026-12-01"
    },
    "status": "draft",
    "signing_order": "sequential",
    "delivery_mode": "email",
    "redirect_url": null,
    "environment": "test",
    "external_id": "deal_4821",
    "external_customer_id": "cust_1093",
    "metadata": {
      "crm_owner": "team-north"
    },
    "rendered_sha256": null,
    "expires_at": null,
    "sent_for_signing_at": null,
    "completed_at": null,
    "cancelled_at": null,
    "personal_data_erased_at": null,
    "created_at": "2026-11-15T10:00:00.000Z",
    "updated_at": "2026-11-15T10:00:00.000Z"
  },
  "template": {
    "id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "slug": "consulting-agreement-dk",
    "version": 3,
    "name_da": "Konsulentaftale",
    "name_en": "Consulting agreement",
    "signing_enabled": true
  },
  "fields": [
    {
      "key": "client_name",
      "type": "text",
      "label_da": "Kundens navn",
      "label_en": "Client name",
      "options": null,
      "default_value": null,
      "required": true,
      "depends_on": null,
      "min_value": null,
      "max_value": null,
      "max_field": null
    }
  ],
  "signers": [
    {
      "id": "0f9e8d7c-6b5a-4d3c-8b2a-1f0e9d8c7b6a",
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "role": "Konsulent",
      "sort": 0,
      "status": "pending",
      "signed_at": null,
      "declined_at": null,
      "decline_reason": null,
      "signature_method": null,
      "signature_typed_name": null,
      "reminders_sent": 0,
      "last_reminder_at": null,
      "invited_at": null
    }
  ],
  "data_collection": {
    "id": "3c2b1a0f-9e8d-4c7b-8a6f-5e4d3c2b1a0f",
    "status": "pending",
    "url": "https://legaldock.dk/fill/Vb8x2kQ...",
    "locked_fields": [
      "client_name"
    ],
    "expires_at": "2026-11-22T10:00:00.000Z",
    "first_opened_at": null,
    "submitted_at": null,
    "revoked_at": null,
    "created_at": "2026-11-15T10:00:00.000Z"
  }
}
get/documents/{id}documents:read

Get a document

Document, pinned template summary, field definitions, signers and the latest hosted fill-in link state (data_collection, null if none). Signing tokens and fill-in URLs are never returned here.

  • id (path, required) — Document id (UUID).
curl -X GET 'https://legaldock.dk/api/v1/documents/7d2c1f8e-...' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "document": {
    "id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
    "template_id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "template_slug": "consulting-agreement-dk",
    "template_version": 3,
    "template_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
    "locale": "da",
    "title": "Konsulentaftale: Nordlys ApS",
    "data": {
      "client_name": "Nordlys ApS",
      "consultant_name": "Anna Hansen",
      "start_date": "2026-12-01"
    },
    "status": "draft",
    "signing_order": "sequential",
    "delivery_mode": "email",
    "redirect_url": null,
    "environment": "test",
    "external_id": "deal_4821",
    "external_customer_id": "cust_1093",
    "metadata": {
      "crm_owner": "team-north"
    },
    "rendered_sha256": null,
    "expires_at": null,
    "sent_for_signing_at": null,
    "completed_at": null,
    "cancelled_at": null,
    "personal_data_erased_at": null,
    "created_at": "2026-11-15T10:00:00.000Z",
    "updated_at": "2026-11-15T10:00:00.000Z"
  },
  "template": {
    "id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "slug": "consulting-agreement-dk",
    "version": 3,
    "name_da": "Konsulentaftale",
    "name_en": "Consulting agreement",
    "signing_enabled": true
  },
  "fields": [
    {
      "key": "client_name",
      "type": "text",
      "label_da": "Kundens navn",
      "label_en": "Client name",
      "options": null,
      "default_value": null,
      "required": true,
      "depends_on": null,
      "min_value": null,
      "max_value": null,
      "max_field": null
    }
  ],
  "signers": [
    {
      "id": "0f9e8d7c-6b5a-4d3c-8b2a-1f0e9d8c7b6a",
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "role": "Konsulent",
      "sort": 0,
      "status": "pending",
      "signed_at": null,
      "declined_at": null,
      "decline_reason": null,
      "signature_method": null,
      "signature_typed_name": null,
      "reminders_sent": 0,
      "last_reminder_at": null,
      "invited_at": null
    }
  ]
}
patch/documents/{id}documents:write

Update a draft

Partial update while the document is a draft. data is merged into existing values and validated against the template. Sending signers replaces the whole signer list. While a hosted fill-in link is pending, data cannot be changed (409 DATA_COLLECTION_PENDING); other fields can.

  • id (path, required) — Document id (UUID).
curl -X PATCH 'https://legaldock.dk/api/v1/documents/7d2c1f8e-...' \
  -H 'Authorization: Bearer ldk_test_...' \
  -H 'Content-Type: application/json' \
  -d '{
  "data": {
    "start_date": "2027-01-01"
  },
  "metadata": {
    "crm_owner": "team-south"
  }
}'

Response 200

{
  "document": {
    "id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
    "template_id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "template_slug": "consulting-agreement-dk",
    "template_version": 3,
    "template_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
    "locale": "da",
    "title": "Konsulentaftale: Nordlys ApS",
    "data": {
      "client_name": "Nordlys ApS",
      "consultant_name": "Anna Hansen",
      "start_date": "2026-12-01"
    },
    "status": "draft",
    "signing_order": "sequential",
    "delivery_mode": "email",
    "redirect_url": null,
    "environment": "test",
    "external_id": "deal_4821",
    "external_customer_id": "cust_1093",
    "metadata": {
      "crm_owner": "team-north"
    },
    "rendered_sha256": null,
    "expires_at": null,
    "sent_for_signing_at": null,
    "completed_at": null,
    "cancelled_at": null,
    "personal_data_erased_at": null,
    "created_at": "2026-11-15T10:00:00.000Z",
    "updated_at": "2026-11-15T10:00:00.000Z"
  },
  "template": {
    "id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
    "slug": "consulting-agreement-dk",
    "version": 3,
    "name_da": "Konsulentaftale",
    "name_en": "Consulting agreement",
    "signing_enabled": true
  },
  "fields": [
    {
      "key": "client_name",
      "type": "text",
      "label_da": "Kundens navn",
      "label_en": "Client name",
      "options": null,
      "default_value": null,
      "required": true,
      "depends_on": null,
      "min_value": null,
      "max_value": null,
      "max_field": null
    }
  ],
  "signers": [
    {
      "id": "0f9e8d7c-6b5a-4d3c-8b2a-1f0e9d8c7b6a",
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "role": "Konsulent",
      "sort": 0,
      "status": "pending",
      "signed_at": null,
      "declined_at": null,
      "decline_reason": null,
      "signature_method": null,
      "signature_typed_name": null,
      "reminders_sent": 0,
      "last_reminder_at": null,
      "invited_at": null
    }
  ]
}
post/documents/{id}/senddocuments:write

Send for signing

Validates required fields, seals the document text (SHA-256) and issues fresh per-signer links valid for 14 days. Email mode emails signers in live; embedded mode and every test-environment document send no email and return signing_links instead. signing_links are only returned in this response, store them securely. Live sends are prepaid: each document uses one credit from the partner's balance (one per document, never charged twice); with no credit left the call returns 402 INSUFFICIENT_CREDITS and nothing is sent. While a hosted fill-in link is pending the call returns 409 DATA_COLLECTION_PENDING; submitting the form never sends the document by itself.

  • id (path, required) — Document id (UUID).
curl -X POST 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../send' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "status": "pending_signatures",
  "ok": true,
  "emailed": 0,
  "failed": [],
  "failures": [],
  "sandbox": true,
  "email_suppressed": true,
  "signing_links": [
    {
      "signer_id": "0f9e8d7c-6b5a-4d3c-8b2a-1f0e9d8c7b6a",
      "name": "Anna Hansen",
      "email": "anna@example.dk",
      "signing_url": "https://legaldock.dk/sign/3q2-7xKp..."
    }
  ]
}
post/documents/{id}/data-collectiondocuments:write

Issue a hosted fill-in link

Issues a new single-use link to a LegalDock-hosted form built from the document's template fields, for a draft that has not been signed. Any earlier pending link for the document stops working immediately. Fields you locked when creating the document stay locked. Default expiry 7 days (1-30). The url is returned only in this response; LegalDock stores only a hash of it. On submission the values are validated with the same rules as PATCH and send (all visible required fields must be filled), saved to the document, and document.data_submitted is emitted. The document stays a draft: call /send yourself (this is when embedded signing links are returned and the credit is used). Test-environment links show a TEST banner.

  • id (path, required) — Document id (UUID).
curl -X POST 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../data-collection' \
  -H 'Authorization: Bearer ldk_test_...' \
  -H 'Content-Type: application/json' \
  -d '{
  "expires_in_days": 7
}'

Response 201

{
  "data_collection": {
    "id": "3c2b1a0f-9e8d-4c7b-8a6f-5e4d3c2b1a0f",
    "status": "pending",
    "url": "https://legaldock.dk/fill/Vb8x2kQ...",
    "locked_fields": [
      "client_name"
    ],
    "expires_at": "2026-11-22T10:00:00.000Z",
    "first_opened_at": null,
    "submitted_at": null,
    "revoked_at": null,
    "created_at": "2026-11-15T10:00:00.000Z"
  }
}
delete/documents/{id}/data-collectiondocuments:write

Revoke the hosted fill-in link

Revokes a pending fill-in link so you can supply data through PATCH instead. Idempotent; returns the latest link state (null if none was ever issued). Cancelling the document also revokes it.

  • id (path, required) — Document id (UUID).
curl -X DELETE 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../data-collection' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "data_collection": {
    "id": "3c2b1a0f-9e8d-4c7b-8a6f-5e4d3c2b1a0f",
    "status": "revoked",
    "url": null,
    "locked_fields": [
      "client_name"
    ],
    "expires_at": "2026-11-22T10:00:00.000Z",
    "first_opened_at": null,
    "submitted_at": null,
    "revoked_at": "2026-11-15T11:00:00.000Z",
    "created_at": "2026-11-15T10:00:00.000Z"
  }
}
post/documents/{id}/canceldocuments:write

Cancel a document

Cancels any document that is not completed and revokes a pending hosted fill-in link. Idempotent for already-cancelled documents.

  • id (path, required) — Document id (UUID).
curl -X POST 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../cancel' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "status": "cancelled"
}
post/documents/{id}/signers/{signerId}/reminddocuments:write

Remind a signer

Emails a fresh signing link to a pending signer (the old link stops working). Not available in embedded mode. In the test environment no email is sent, the existing link stays valid, and the response has sandbox: true.

  • id (path, required) — Document id (UUID).
  • signerId (path, required)
curl -X POST 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../signers/0f9e8d7c-.../remind' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "ok": true
}
get/documents/{id}/auditdocuments:read

Audit trail

Hash-chained audit events, oldest first. Each event's hash covers its content and the previous hash. Events with redacted_at were redacted on an erasure request: their hashes are kept so the chain linkage still verifies, but their content can no longer be re-hashed.

  • id (path, required) — Document id (UUID).
curl -X GET 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../audit' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "events": [
    {
      "id": "5e4d3c2b-1a0f-4e9d-8c7b-6a5f4e3d2c1b",
      "document_id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
      "event_type": "document.created",
      "actor_type": "partner",
      "actor_user_id": null,
      "partner_id": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
      "api_key_id": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
      "actor_email": null,
      "actor_name": null,
      "ip_address": "203.0.113.7",
      "user_agent": "acme-crm/2.1",
      "data": null,
      "prev_hash": "",
      "hash": "b1946ac92492d2347c6235b4d2611184...",
      "created_at": "2026-11-15T10:00:00.000Z",
      "redacted_at": null
    }
  ]
}
get/documents/{id}/pdfdocuments:read

Download signed PDF

Available only for completed documents. Returns application/pdf.

  • id (path, required) — Document id (UUID).
curl -X GET 'https://legaldock.dk/api/v1/documents/7d2c1f8e-.../pdf' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

<binary PDF>

Customers

get/customers/{customerId}/exportcustomers:manage

Export a customer's data

Every document (including data and rendered text), signer and audit event with this external_customer_id in the key's environment, oldest first, cursor paginated. Use it to answer access and portability requests. Already-erased documents no longer carry the customer id and are not included.

  • customerId (path, required) — Your external_customer_id, URL-encoded (1-200 characters).
  • limit (query)
  • cursor (query)
curl -X GET 'https://legaldock.dk/api/v1/customers/cust_1093/export' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "format_version": "2026-11-15",
  "exported_at": "2026-11-15T12:00:00.000Z",
  "environment": "live",
  "external_customer_id": "cust_1093",
  "documents": [
    {
      "id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
      "template_id": "4b3a2c1d-0e9f-4a8b-9c7d-6e5f4a3b2c1d",
      "template_slug": "consulting-agreement-dk",
      "template_version": 3,
      "template_version_id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
      "locale": "da",
      "title": "Konsulentaftale: Nordlys ApS",
      "data": {
        "client_name": "Nordlys ApS",
        "consultant_name": "Anna Hansen",
        "start_date": "2026-12-01"
      },
      "status": "draft",
      "signing_order": "sequential",
      "delivery_mode": "email",
      "redirect_url": null,
      "environment": "live",
      "external_id": "deal_4821",
      "external_customer_id": "cust_1093",
      "metadata": {
        "crm_owner": "team-north"
      },
      "rendered_sha256": null,
      "expires_at": null,
      "sent_for_signing_at": null,
      "completed_at": null,
      "cancelled_at": null,
      "personal_data_erased_at": null,
      "created_at": "2026-11-15T10:00:00.000Z",
      "updated_at": "2026-11-15T10:00:00.000Z",
      "rendered_html": null,
      "signers": [
        {
          "id": "0f9e8d7c-6b5a-4d3c-8b2a-1f0e9d8c7b6a",
          "name": "Anna Hansen",
          "email": "anna@example.dk",
          "role": "Konsulent",
          "sort": 0,
          "status": "pending",
          "signed_at": null,
          "declined_at": null,
          "decline_reason": null,
          "signature_method": null,
          "signature_typed_name": null,
          "reminders_sent": 0,
          "last_reminder_at": null,
          "invited_at": null
        }
      ],
      "audit_events": []
    }
  ],
  "next_cursor": null
}
delete/customers/{customerId}customers:manage

Erase a customer's data

Processes up to 100 matching documents per call in the key's environment; call again while has_more is true. Per document: draft, cancelled or expired documents that were never sent or finalised are deleted outright; completed documents, and documents that were sent and later cancelled or expired, are redacted (names, emails, IP addresses, user agents, signatures, form data, metadata, title, rendered text and the customer id are removed; status, timestamps, template version, the SHA-256 fingerprint and audit hashes remain); documents awaiting signatures are skipped (cancel them first). Export before erasing if you must retain a copy.

  • customerId (path, required) — Your external_customer_id, URL-encoded (1-200 characters).
curl -X DELETE 'https://legaldock.dk/api/v1/customers/cust_1093' \
  -H 'Authorization: Bearer ldk_test_...'

Response 200

{
  "environment": "live",
  "summary": {
    "deleted": 1,
    "redacted": 1,
    "already_erased": 0,
    "skipped_in_progress": 1,
    "not_found": 0
  },
  "documents": [
    {
      "document_id": "7d2c1f8e-3b4a-4c6d-9e1f-2a3b4c5d6e7f",
      "external_id": "deal_4821",
      "previous_status": "draft",
      "outcome": "deleted"
    },
    {
      "document_id": "8e7d6c5b-4a3f-4e2d-9c1b-0a9f8e7d6c5b",
      "external_id": "deal_4790",
      "previous_status": "completed",
      "outcome": "redacted"
    },
    {
      "document_id": "9f8e7d6c-5b4a-4f3e-8d2c-1b0a9f8e7d6c",
      "external_id": "deal_4833",
      "previous_status": "pending_signatures",
      "outcome": "skipped_in_progress"
    }
  ],
  "has_more": false
}

Webhooks

Configure HTTPS endpoints in the partner portal. Each endpoint has its own signing secret, shown once. Only documents created through the API emit events.

document.createddocument.sentsigner.viewedsigner.signedsigner.declineddocument.completeddocument.expireddocument.cancelleddocument.data_submitted
  • Header LegalDock-Signature: t=<unix>,v1=<hex> is HMAC-SHA256 of `${t}.${rawBody}` with your secret. Reject timestamps older than 5 minutes.
  • Respond 2xx within 10 seconds. Redirects are not followed.
  • Failed deliveries are retried after 1 min, 5 min, 15 min, 1 h and 4 h (6 attempts in total), then marked exhausted. You can redeliver any delivery from the portal.
  • After rotating a secret, deliveries queued before the rotation keep using the previous secret for up to 24 hours; new deliveries use the new secret.
  • Endpoint hosts must resolve to public IP addresses, checked at setup and before every attempt.
{
  "id": "3c9f2d1e-8b7a-4c6d-9e0f-1a2b3c4d5e6f",
  "type": "signer.signed",
  "created_at": "2026-11-15T10:20:00.000Z",
  "environment": "test",
  "livemode": false,
  "data": {
    "document": {
      "id": "7d2c1f8e-...",
      "external_id": "deal_4821",
      "external_customer_id": "cust_1093",
      "status": "partially_signed",
      "...": "..."
    },
    "signer": {
      "id": "0f9e8d7c-...",
      "status": "signed",
      "signed_at": "2026-11-15T10:20:00.000Z",
      "declined_at": null,
      "first_viewed_at": "2026-11-15T10:15:00.000Z"
    }
  }
}
import crypto from "node:crypto";

// rawBody: the exact bytes you received, before JSON.parse
export function verifyLegalDock(rawBody, header, secret, toleranceSeconds = 300) {
  const t = Number(/(?:^|,)t=(\d+)/.exec(header)?.[1]);
  const v1 = /(?:^|,)v1=([0-9a-f]{64})/.exec(header)?.[1];
  if (!t || !v1 || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  return crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}

// Then: const event = JSON.parse(rawBody);
// if (event.environment === "test") { /* sandbox branch */ }
// Deduplicate on event.id — retries and redeliveries reuse it.