{
  "info": {
    "name": "Stampa Public API",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "OAuth2 client-credentials examples for Stampa public API integrations."
  },
  "variable": [
    { "key": "base_url", "value": "https://admin.stamping.co.il" },
    { "key": "client_id", "value": "" },
    { "key": "client_secret", "value": "" },
    { "key": "access_token", "value": "" },
    { "key": "template_id", "value": "00000000-0000-0000-0000-000000000000" },
    { "key": "envelope_id", "value": "00000000-0000-0000-0000-000000000000" },
    { "key": "external_reference", "value": "crm-agreement-001" },
    { "key": "webhook_id", "value": "00000000-0000-0000-0000-000000000000" },
    { "key": "delivery_id", "value": "00000000-0000-0000-0000-000000000000" }
  ],
  "item": [
    {
      "name": "OAuth token",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/x-www-form-urlencoded" },
          { "key": "X-Request-Id", "value": "postman-token-001" }
        ],
        "auth": {
          "type": "basic",
          "basic": [
            { "key": "username", "value": "{{client_id}}", "type": "string" },
            { "key": "password", "value": "{{client_secret}}", "type": "string" }
          ]
        },
        "url": "{{base_url}}/oauth/token",
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            { "key": "grant_type", "value": "client_credentials", "type": "text" },
            { "key": "scope", "value": "organization.read usage.read templates.read files.write envelopes.read envelopes.write webhooks.manage", "type": "text" }
          ]
        }
      }
    },
    {
      "name": "List templates",
      "request": {
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-templates-001" }
        ],
        "url": "{{base_url}}/api/v1/templates"
      }
    },
    {
      "name": "Get template",
      "request": {
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-template-001" }
        ],
        "url": "{{base_url}}/api/v1/templates/{{template_id}}"
      }
    },
    {
      "name": "Create envelope from template",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Request-Id", "value": "postman-envelope-create-001" },
          { "key": "Idempotency-Key", "value": "{{external_reference}}" }
        ],
        "url": "{{base_url}}/api/v1/envelopes/from-template",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"title\": \"NDA for ACME Ltd\",\n  \"workflowType\": \"Sequential\",\n  \"templateId\": \"{{template_id}}\",\n  \"expiresAt\": \"2026-10-11T10:00:00Z\",\n  \"externalReference\": \"{{external_reference}}\",\n  \"externalSystem\": \"igates-crm\",\n  \"externalMetadataJson\": \"{\\\"crmRecordId\\\":\\\"crm-123\\\",\\\"agreementRequestId\\\":\\\"agr-456\\\"}\",\n  \"recipients\": [\n    {\n      \"roleName\": \"Customer signer\",\n      \"fullName\": \"Dana Cohen\",\n      \"email\": \"dana@example.com\",\n      \"phone\": \"+972501234567\",\n      \"signingOrder\": 1,\n      \"deliveryChannel\": \"Email\",\n      \"authenticationMethod\": \"SecureLink\",\n      \"type\": \"Signer\",\n      \"language\": \"he\"\n    }\n  ],\n  \"initialValues\": []\n}"
        }
      }
    },
    {
      "name": "Recover envelope by external reference",
      "request": {
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-recover-001" }
        ],
        "url": "{{base_url}}/api/v1/envelopes/by-external-reference/{{external_reference}}"
      }
    },
    {
      "name": "Send envelope",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-envelope-send-001" },
          { "key": "Idempotency-Key", "value": "{{external_reference}}-send" }
        ],
        "url": "{{base_url}}/api/v1/envelopes/{{envelope_id}}/send"
      }
    },
    {
      "name": "Download final PDF",
      "request": {
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-final-pdf-001" }
        ],
        "url": "{{base_url}}/api/v1/envelopes/{{envelope_id}}/documents/final-pdf"
      }
    },
    {
      "name": "Create webhook",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Request-Id", "value": "postman-webhook-create-001" }
        ],
        "url": "{{base_url}}/api/v1/webhooks",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"name\": \"CRM webhook\",\n  \"url\": \"https://crm.example.com/webhooks/stampa\",\n  \"events\": [\"envelope.created\", \"envelope.sent\", \"envelope.completed\", \"document.final_pdf_ready\"]\n}"
        }
      }
    },
    {
      "name": "Test webhook",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-webhook-test-001" },
          { "key": "Idempotency-Key", "value": "postman-webhook-test-001" }
        ],
        "url": "{{base_url}}/api/v1/webhooks/{{webhook_id}}/test"
      }
    },
    {
      "name": "Replay webhook delivery",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Request-Id", "value": "postman-webhook-replay-001" },
          { "key": "Idempotency-Key", "value": "postman-webhook-replay-001" }
        ],
        "url": "{{base_url}}/api/v1/webhooks/deliveries/{{delivery_id}}/replay"
      }
    },
    {
      "name": "Sandbox simulate completed",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{access_token}}" },
          { "key": "X-Stampa-Sandbox", "value": "true" },
          { "key": "X-Request-Id", "value": "postman-sandbox-completed-001" }
        ],
        "url": "{{base_url}}/api/v1/sandbox/envelopes/{{envelope_id}}/Completed"
      }
    }
  ]
}
