{
  "info": {
    "_postman_id": "c8f1a4b2-1a7d-4e3a-9a01-mezdoc20260519",
    "name": "Mezdoc REST API",
    "description": "Mezdoc REST API collection for PDF templates, structured renders, and workflow runs. Import this collection, set the `baseUrl` and `token` variables in the Mezdoc environment, then hit Send on any request.\n\nDocs: https://mezdoc.com/developers\nStatus: MVP. Endpoints listed here are the developer surface for launch.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      { "key": "token", "value": "{{token}}", "type": "string" }
    ]
  },
  "item": [
    {
      "name": "Workflows",
      "description": "Workflow runs. A workflow chains structured and dynamic templates into one ordered, condition-gated, signable run.",
      "item": [
        {
          "name": "Create a workflow run",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Idempotency-Key", "value": "{{$guid}}", "description": "Retry-safe key. Repeat calls with the same key return the same run within 24h." }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"environment\": \"production\",\n  \"callback_url\": \"https://example.com/webhooks/mezdoc\",\n  \"field_data\": {\n    \"policyholder_name\": \"Acme Logistics Pvt Ltd\",\n    \"policy_number\": \"POL-2026-00481\",\n    \"effective_date\": \"2026-06-01\",\n    \"sum_insured\": 1500000,\n    \"vehicle_or_property_id\": \"MH12-AB-3344\",\n    \"customer_signature\": {\n      \"data_url\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA...\",\n      \"signer_name\": \"Priya Mehta\",\n      \"signer_email\": \"priya@example.com\"\n    }\n  }\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/workflows/:aliasOrId/runs",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "workflows", ":aliasOrId", "runs"],
              "variable": [
                { "key": "aliasOrId", "value": "insurance_coi_pack", "description": "Workflow alias or ID." }
              ]
            },
            "description": "Create a run for the given workflow. The server validates `field_data` against the workflow's field schema (the env-pinned version), enqueues a render job, and returns `{ run_id, status }` immediately.\n\nReturns `202 Accepted` on success. Poll the status endpoint or wait for the `run.completed` webhook."
          },
          "response": [
            {
              "name": "Accepted",
              "status": "Accepted",
              "code": 202,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"run_id\": \"run_01HW9XK7M3N5JEMZD0CMPL3T3\",\n  \"status\": \"queued_for_render\",\n  \"environment\": \"production\",\n  \"created_at\": \"2026-05-19T10:00:00Z\"\n}"
            }
          ]
        },
        {
          "name": "Get run status",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/workflows/runs/:runId",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "workflows", "runs", ":runId"],
              "variable": [
                { "key": "runId", "value": "run_01HW9XK7M3N5JEMZD0CMPL3T3" }
              ]
            },
            "description": "Poll a run until it reaches `completed`. Returns the run status plus signed download URLs once ready (1h TTL, regenerated on every read)."
          },
          "response": [
            {
              "name": "Completed",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"run_id\": \"run_01HW9XK7M3N5JEMZD0CMPL3T3\",\n  \"status\": \"completed\",\n  \"completed_at\": \"2026-05-19T10:00:02Z\",\n  \"pdfs\": [\n    { \"document_id\": \"doc_coi\",       \"url\": \"https://files.mezdoc.com/run_.../coi.pdf\",       \"page_count\": 1 },\n    { \"document_id\": \"doc_endorsement\",\"url\": \"https://files.mezdoc.com/run_.../endorsement.pdf\",\"page_count\": 2 }\n  ],\n  \"merged_pdf_url\": \"https://files.mezdoc.com/run_.../merged.pdf\"\n}"
            }
          ]
        },
        {
          "name": "Download one document PDF",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/workflows/runs/:runId/pdf?doc=1",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "workflows", "runs", ":runId", "pdf"],
              "query": [
                { "key": "doc", "value": "1", "description": "1-indexed position of the document in the workflow." }
              ],
              "variable": [
                { "key": "runId", "value": "run_01HW9XK7M3N5JEMZD0CMPL3T3" }
              ]
            },
            "description": "Redirects to a signed download URL for one document PDF from the run. Use the `doc` query param to pick which document."
          },
          "response": []
        },
        {
          "name": "Download merged PDF",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/workflows/runs/:runId/merged",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "workflows", "runs", ":runId", "merged"],
              "variable": [
                { "key": "runId", "value": "run_01HW9XK7M3N5JEMZD0CMPL3T3" }
              ]
            },
            "description": "Redirects to a signed download URL for the merged packet PDF (all included documents in workflow order, plus the optional cover page)."
          },
          "response": []
        },
        {
          "name": "Get run audit trail",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/workflows/runs/:runId/audit",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "workflows", "runs", ":runId", "audit"],
              "variable": [
                { "key": "runId", "value": "run_01HW9XK7M3N5JEMZD0CMPL3T3" }
              ]
            },
            "description": "Returns the run timeline plus every SignatureRecord (signer name, signer email, IP, user-agent, signed-at, SHA-256 hash of the final rendered PDF). Use this for compliance proofs."
          },
          "response": [
            {
              "name": "Audit",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"run_id\": \"run_01HW9XK7M3N5JEMZD0CMPL3T3\",\n  \"events\": [\n    { \"kind\": \"created\",   \"at\": \"2026-05-19T10:00:00Z\" },\n    { \"kind\": \"rendered\",  \"at\": \"2026-05-19T10:00:01Z\" },\n    { \"kind\": \"signed\",    \"at\": \"2026-05-19T10:00:02Z\" },\n    { \"kind\": \"completed\", \"at\": \"2026-05-19T10:00:02Z\" }\n  ],\n  \"signatures\": [\n    {\n      \"workflow_field_alias\": \"customer_signature\",\n      \"signer_name\":  \"Priya Mehta\",\n      \"signer_email\": \"priya@example.com\",\n      \"ip\": \"103.21.244.10\",\n      \"user_agent\": \"Mozilla/5.0 ...\",\n      \"signed_at\": \"2026-05-19T10:00:02Z\",\n      \"document_hash_sha256\": \"9b1f3a...\"\n    }\n  ]\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "Templates",
      "description": "Structured (PDF-overlay) and dynamic (Tiptap) templates. Templates are the building blocks workflows compose.",
      "item": [
        {
          "name": "List templates",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/templates",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "templates"]
            },
            "description": "List every template in the calling org. Both structured and dynamic templates are returned with their kind, alias, and live version number per environment."
          },
          "response": []
        },
        {
          "name": "Render a structured template (one-shot)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "Idempotency-Key", "value": "{{$guid}}" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"environment\": \"production\",\n  \"data\": {\n    \"policyholder_name\": \"Acme Logistics Pvt Ltd\",\n    \"policy_number\":     \"POL-2026-00481\",\n    \"effective_date\":    \"2026-06-01\",\n    \"sum_insured\":       1500000,\n    \"vehicle_or_property_id\": \"MH12-AB-3344\"\n  }\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/templates/:alias/submissions",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "templates", ":alias", "submissions"],
              "variable": [
                { "key": "alias", "value": "coi_v3", "description": "Template alias (snake_case)." }
              ]
            },
            "description": "One-shot structured template render. POST your JSON, get back a submission ID. The PDF is delivered via signed webhook (`pdf.generation.completed`) or polled via the submission status endpoint."
          },
          "response": [
            {
              "name": "Accepted",
              "status": "Accepted",
              "code": 202,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"submission_id\": \"sub_01HW9XK7M3N5JEMZD0CMPL3T3\",\n  \"status\": \"processing\",\n  \"webhook\": \"pdf.generation.completed\"\n}"
            }
          ]
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.mezdoc.com",
      "type": "string",
      "description": "Mezdoc API base URL. Override in your environment for staging."
    },
    {
      "key": "token",
      "value": "tk_live_REPLACE_ME",
      "type": "string",
      "description": "Your bearer API token. Create one in the Mezdoc dashboard, scope it to a template or workflow, and paste it here."
    }
  ]
}
