{
  "info": {
    "_postman_id": "fefb8e23-4d30-4b7a-8ea4-c4ddbe8e249d",
    "name": "AddressMask API — Production Integration",
    "description": "Import-ready collection for the platform-independent AddressMask shipping workflow. It covers merchant permission requests, consumer approval polling, shipment-bound delivery requests, one-use token issuance, resolver disclosure, signed webhook management, optional delivery lifecycle events, replay checks, and cleanup.\n\nBefore running requests, set the blank configuration and credential variables in a private Postman environment. Never commit or share live `amk_…`, `amt_…`, or `whsec_…` values.\n\nRun `00 — Start a new shipping test run` before each distinct order. After creating a permission request, the consumer must approve it in AddressMask; then rerun `Get permission request` until its status is `APPROVED` and `policy_id` is populated.\n\nA mask is public, an API key authenticates a system, and an access token authorizes one exact disclosure. Merchant keys must never resolve tokens, and resolver keys must never create permission requests or tokens.",
    "schema": "https://schema.postman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "00 — Setup and contract",
      "description": "Start here. This folder initializes a fresh logical workflow without changing credentials or tenant configuration.",
      "item": [
        {
          "name": "00 — Start a new shipping test run",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const guid = () => pm.variables.replaceIn('{{$guid}}');",
                  "const now = Date.now();",
                  "pm.collectionVariables.set('workflow_run_id', guid());",
                  "pm.collectionVariables.set('shipment_ref', `POSTMAN-ORDER-${now}`);",
                  "pm.collectionVariables.set('permission_expires_at', new Date(now + 24 * 60 * 60 * 1000).toISOString());",
                  "pm.collectionVariables.set('permission_request_id', '');",
                  "pm.collectionVariables.set('policy_id', '');",
                  "pm.collectionVariables.set('delivery_request_id', '');",
                  "pm.collectionVariables.set('token_id', '');",
                  "pm.collectionVariables.set('access_token', '');",
                  "pm.collectionVariables.set('token_expires_at', '');",
                  "pm.collectionVariables.set('resolution_id', '');",
                  "pm.collectionVariables.set('last_request_id', '');",
                  "pm.collectionVariables.set('permission_idempotency_key', `permission-${guid()}`);",
                  "pm.collectionVariables.set('delivery_idempotency_key', `delivery-${guid()}`);",
                  "pm.collectionVariables.set('token_idempotency_key', `token-${guid()}`);",
                  "pm.collectionVariables.set('resolution_idempotency_key', `resolution-${guid()}`);",
                  "pm.collectionVariables.set('resolution_replay_idempotency_key', `resolution-replay-${guid()}`);",
                  "pm.collectionVariables.set('webhook_idempotency_key', `webhook-${guid()}`);",
                  "pm.collectionVariables.set('webhook_replay_idempotency_key', `webhook-replay-${guid()}`);",
                  "pm.collectionVariables.set('webhook_rotate_idempotency_key', `webhook-rotate-${guid()}`);",
                  "pm.collectionVariables.set('webhook_deactivate_idempotency_key', `webhook-deactivate-${guid()}`);",
                  "pm.collectionVariables.set('delivery_event_idempotency_key', `delivery-event-${guid()}`);",
                  "pm.collectionVariables.set('delivery_event_id', `postman-${now}`);",
                  "pm.collectionVariables.set('permission_revoke_idempotency_key', `permission-revoke-${guid()}`);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('OpenAPI contract is reachable', () => pm.response.to.have.status(200));",
                  "const contract = pm.response.json();",
                  "pm.test('Contract is OpenAPI 3.1', () => pm.expect(contract.openapi).to.eql('3.1.0'));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/openapi",
            "description": "Generates a fresh shipment reference, expiry, and stable idempotency keys for one logical test order, then verifies that the deployment's capability-filtered OpenAPI document is reachable. It does not clear configuration or credential variables."
          }
        }
      ]
    },
    {
      "name": "01 — Merchant permission",
      "description": "The merchant asks the consumer for exact, expiring shipping permission. A `201 PENDING` response is not authorization. The consumer approves in the AddressMask UI; the merchant then reads the request until it becomes `APPROVED`.",
      "item": [
        {
          "name": "List permission requests",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Permission requests are returned', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test('Response has a request ID', () => pm.expect(body.request_id).to.be.a('string'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{permission_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/permission-requests?organization_id={{organization_id}}&environment={{environment}}",
            "description": "Uses a merchant key with `permission-requests:manage`. This endpoint returns permission metadata, never an address or access token."
          }
        },
        {
          "name": "Create permission request",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Permission request is created', () => pm.response.to.have.status(201));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('permission_request_id', body.data.permission_request_id);",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "pm.test('Permission is pending', () => pm.expect(body.data.status).to.eql('PENDING'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{permission_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{permission_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"organization_id\": \"{{organization_id}}\",\n  \"requesting_client_id\": \"{{merchant_client_id}}\",\n  \"mask\": \"{{address_mask}}\",\n  \"resolver_client_id\": \"{{resolver_client_id}}\",\n  \"purpose\": \"SHIPPING\",\n  \"audience\": {\n    \"type\": \"resolver\",\n    \"id\": \"{{resolver_client_id}}\"\n  },\n  \"requested_fields\": [\"full_delivery_address\"],\n  \"request_reason\": \"{{request_reason}}\",\n  \"requested_expires_at\": \"{{permission_expires_at}}\",\n  \"max_resolution_uses\": 1\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/permission-requests",
            "description": "Creates one immutable request for the exact mask, organization, merchant client, resolver, purpose, field, and expiry. Rerunning this exact request with the same idempotency key is a safe replay."
          }
        },
        {
          "name": "Get permission request",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Permission request is readable', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "const permission = body.data.permission_request;",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "if (permission.status === 'APPROVED' && permission.authorization) {",
                  "  pm.collectionVariables.set('policy_id', permission.authorization.policy_id);",
                  "} else {",
                  "  console.warn(`Permission is ${permission.status}. The consumer must approve it before delivery and token requests can succeed.`);",
                  "}",
                  "pm.test('Permission status is recognized', () => pm.expect(['PENDING', 'APPROVED', 'DENIED', 'REVOKED', 'EXPIRED']).to.include(permission.status));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{permission_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/permission-requests/{{permission_request_id}}?organization_id={{organization_id}}",
            "description": "Run after the consumer decides. When the request is approved, the post-response script saves `policy_id` for the shipping workflow. Consumer approval is deliberately not automated with a merchant API key."
          },
          "response": [
            {
              "name": "200 — Permission approved",
              "originalRequest": {
                "method": "GET",
                "header": [
                  {
                    "key": "Accept",
                    "value": "application/json"
                  }
                ],
                "url": "{{base_url}}/api/v1/permission-requests/{{permission_request_id}}?organization_id={{organization_id}}"
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n  \"data\": {\n    \"permission_request\": {\n      \"id\": \"perm_example_123\",\n      \"mask\": \"AM-EXAMPLE123\",\n      \"status\": \"APPROVED\",\n      \"purpose\": \"SHIPPING\",\n      \"requested_fields\": [\"full_delivery_address\"],\n      \"authorization\": {\n        \"policy_id\": \"pol_example_123\",\n        \"expires_at\": \"2026-10-13T12:00:00.000Z\",\n        \"max_token_ttl_seconds\": 86400\n      }\n    },\n    \"capability_enabled\": true\n  },\n  \"request_id\": \"req_example_permission\"\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "02 — Shipping delivery and token",
      "description": "Run only after `Get permission request` reports `APPROVED` and stores `policy_id`. Each distinct shipment gets a unique `shipment_ref`, delivery request, and one-use access token.",
      "item": [
        {
          "name": "Create delivery request",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.variables.get('policy_id')) throw new Error('policy_id is empty. Approve the permission and rerun Get permission request first.');"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Delivery request is created', () => pm.response.to.have.status(201));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('delivery_request_id', body.data.delivery_request_id);",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "pm.test('Delivery starts pending', () => pm.expect(body.data.status).to.eql('PENDING'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{delivery_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"mask\": \"{{address_mask}}\",\n  \"policy_id\": \"{{policy_id}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/delivery-requests",
            "description": "Uses a merchant key with `tokens:create`. The delivery request binds the approved policy to one merchant shipment reference."
          },
          "response": [
            {
              "name": "201 — Delivery request pending",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"mask\": \"{{address_mask}}\",\n  \"policy_id\": \"{{policy_id}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\"\n}"
                },
                "url": "{{base_url}}/api/v1/delivery-requests"
              },
              "status": "Created",
              "code": 201,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n  \"data\": {\n    \"delivery_request_id\": \"del_example_123\",\n    \"status\": \"PENDING\"\n  },\n  \"request_id\": \"req_example_delivery\"\n}"
            }
          ]
        },
        {
          "name": "Issue one-use resolver token",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.variables.get('delivery_request_id')) throw new Error('delivery_request_id is empty. Create the delivery request first.');"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Access token is issued', () => pm.response.to.have.status(201));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('token_id', body.data.token_id);",
                  "pm.collectionVariables.set('access_token', body.data.token);",
                  "pm.collectionVariables.set('token_expires_at', body.data.expires_at);",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "pm.test('Token is active and shipping-scoped', () => {",
                  "  pm.expect(body.data.status).to.eql('ACTIVE');",
                  "  pm.expect(body.data.purpose).to.eql('SHIPPING');",
                  "  pm.expect(body.data.requested_fields).to.eql(['full_delivery_address']);",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{token_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"policy_id\": \"{{policy_id}}\",\n  \"purpose\": \"SHIPPING\",\n  \"audience\": {\n    \"type\": \"resolver\",\n    \"id\": \"{{resolver_client_id}}\"\n  },\n  \"delivery_request_id\": \"{{delivery_request_id}}\",\n  \"requested_fields\": [\"full_delivery_address\"],\n  \"expires_in_seconds\": {{token_ttl_seconds}},\n  \"use_limit\": 1\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/masks/{{address_mask}}/tokens",
            "description": "Uses a merchant key with `tokens:create`. The returned `amt_…` secret is shown once, short-lived, resolver-bound, field-scoped, and single-use. The post-response script stores it only so the next resolver request can be tested."
          },
          "response": [
            {
              "name": "201 — One-use resolver token issued",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"policy_id\": \"{{policy_id}}\",\n  \"purpose\": \"SHIPPING\",\n  \"audience\": {\n    \"type\": \"resolver\",\n    \"id\": \"{{resolver_client_id}}\"\n  },\n  \"delivery_request_id\": \"{{delivery_request_id}}\",\n  \"requested_fields\": [\"full_delivery_address\"],\n  \"expires_in_seconds\": {{token_ttl_seconds}},\n  \"use_limit\": 1\n}"
                },
                "url": "{{base_url}}/api/v1/masks/{{address_mask}}/tokens"
              },
              "status": "Created",
              "code": 201,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n  \"data\": {\n    \"token_id\": \"tok_example_123\",\n    \"token\": \"<access-token>\",\n    \"status\": \"ACTIVE\",\n    \"purpose\": \"SHIPPING\",\n    \"requested_fields\": [\"full_delivery_address\"],\n    \"expires_at\": \"2026-10-12T12:00:00.000Z\"\n  },\n  \"request_id\": \"req_example_token\"\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "03 — Authorized resolver",
      "description": "Only the authorized resolver receives the access token and exchanges it over a protected server-to-server channel. The resolver authenticates with its own `resolutions:create` API key.",
      "item": [
        {
          "name": "Resolve shipping address",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.variables.get('access_token')) throw new Error('access_token is empty. Issue a token first.');"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Resolution is allowed', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('resolution_id', body.data.resolution_id);",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "pm.test('One address is released and the token is consumed', () => {",
                  "  pm.expect(body.data.decision).to.eql('ALLOW');",
                  "  pm.expect(body.data.result.address).to.be.an('object');",
                  "  pm.expect(body.data.consumed).to.eql(true);",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{resolver_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{resolution_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"token\": \"{{access_token}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\",\n  \"requested_fields\": [\"full_delivery_address\"]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/resolutions",
            "description": "Uses a resolver client key with `resolutions:create`. A successful shipping resolution atomically consumes the one-use access token."
          },
          "response": [
            {
              "name": "200 — Address resolved (sanitized)",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"token\": \"{{access_token}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\",\n  \"requested_fields\": [\"full_delivery_address\"]\n}"
                },
                "url": "{{base_url}}/api/v1/resolutions"
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n  \"data\": {\n    \"decision\": \"ALLOW\",\n    \"resolution_id\": \"res_example_123\",\n    \"result\": {\n      \"address\": {\n        \"recipient_name\": \"Example Customer\",\n        \"line1\": \"123 Example Street\",\n        \"line2\": null,\n        \"city\": \"Boston\",\n        \"state\": \"MA\",\n        \"postal_code\": \"02108\",\n        \"country_code\": \"US\"\n      }\n    },\n    \"consumed\": true\n  },\n  \"request_id\": \"req_example_resolution\"\n}"
            }
          ]
        },
        {
          "name": "Negative — reuse consumed token",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Consumed token is unavailable', () => pm.response.to.have.status(404));",
                  "const body = pm.response.json();",
                  "pm.test('Error is deliberately generic', () => pm.expect(body.error.code).to.eql('TOKEN_UNAVAILABLE'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{resolver_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{resolution_replay_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"token\": \"{{access_token}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\",\n  \"requested_fields\": [\"full_delivery_address\"]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/resolutions",
            "description": "Uses a different idempotency key for a genuinely separate attempt. After a successful one-use resolution, the API must return `404 TOKEN_UNAVAILABLE` without revealing whether the token was consumed, expired, revoked, or invalid."
          },
          "response": [
            {
              "name": "404 — Token already consumed",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"token\": \"{{access_token}}\",\n  \"shipment_ref\": \"{{shipment_ref}}\",\n  \"requested_fields\": [\"full_delivery_address\"]\n}"
                },
                "url": "{{base_url}}/api/v1/resolutions"
              },
              "status": "Not Found",
              "code": 404,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n  \"error\": {\n    \"code\": \"TOKEN_UNAVAILABLE\",\n    \"message\": \"The requested credential is unavailable.\"\n  },\n  \"request_id\": \"req_example_consumed\"\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "04 — Webhooks",
      "description": "Webhook management uses a bearer key with `webhooks:manage`. AddressMask signs deliveries and sends them at least once. Verify the signature over the raw request body and deduplicate by the AddressMask event ID.",
      "item": [
        {
          "name": "Create webhook subscription",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.variables.get('webhook_endpoint')) throw new Error('webhook_endpoint is empty. Set a public HTTPS receiver such as your unique webhook.site URL.');"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Webhook subscription is created', () => pm.response.to.have.status(201));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('webhook_id', body.data.webhook_id);",
                  "pm.collectionVariables.set('webhook_signing_secret', body.data.signing_secret);",
                  "pm.collectionVariables.set('last_request_id', body.request_id);",
                  "pm.test('Signing secret is returned once', () => pm.expect(body.data.signing_secret).to.match(/^whsec_/));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{webhook_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"organization_id\": \"{{organization_id}}\",\n  \"endpoint\": \"{{webhook_endpoint}}\",\n  \"events\": [\n    \"token.created\",\n    \"resolution.allowed\",\n    \"resolution.denied\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/webhooks",
            "description": "Creates the same event subscription exercised during the integration test. Copy the returned signing secret into a real secret manager; it is not returned by list operations."
          }
        },
        {
          "name": "List webhook subscriptions",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Webhook subscriptions are returned', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test('Signing secrets are not listed', () => pm.expect(JSON.stringify(body)).not.to.include('signing_secret'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/webhooks?organization_id={{organization_id}}"
          }
        },
        {
          "name": "List webhook delivery attempts",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Webhook delivery ledger is returned', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "if (body.data.length > 0) pm.collectionVariables.set('webhook_delivery_id', body.data[0].delivery_id);",
                  "pm.test('Ledger does not expose event payloads or secrets', () => {",
                  "  const text = JSON.stringify(body);",
                  "  pm.expect(text).not.to.include('signing_secret');",
                  "  pm.expect(text).not.to.include('full_delivery_address');",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/webhooks/{{webhook_id}}/deliveries?organization_id={{organization_id}}&limit=50",
            "description": "Returns a redacted delivery ledger. If attempts exist, the post-response script captures the first `delivery_id` for the optional replay request."
          }
        },
        {
          "name": "Replay dead-lettered webhook delivery",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.variables.get('webhook_delivery_id')) throw new Error('webhook_delivery_id is empty. List delivery attempts and choose a dead-lettered delivery first.');"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Replay is queued or safely rejected', () => pm.expect([200, 409, 503]).to.include(pm.response.code));",
                  "if (pm.response.code === 200) pm.test('Replay is pending', () => pm.expect(pm.response.json().data.status).to.eql('PENDING'));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{webhook_replay_idempotency_key}}"
              }
            ],
            "url": "{{base_url}}/api/v1/webhooks/{{webhook_id}}/deliveries/{{webhook_delivery_id}}/replay?organization_id={{organization_id}}",
            "description": "Only dead-lettered deliveries are replayable. `409` means the selected delivery is not replayable; `503` means webhook delivery is capability-gated in this deployment."
          }
        },
        {
          "name": "Rotate webhook signing secret",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Signing secret is rotated', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('webhook_signing_secret', body.data.signing_secret);",
                  "pm.test('A new signing secret is returned once', () => pm.expect(body.data.signing_secret).to.match(/^whsec_/));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{webhook_rotate_idempotency_key}}"
              }
            ],
            "url": "{{base_url}}/api/v1/webhooks/{{webhook_id}}/rotate-secret?organization_id={{organization_id}}",
            "description": "Optional operational test. Update your receiver's secret immediately after rotation. Bearer API clients do not require interactive step-up; browser sessions do."
          }
        }
      ]
    },
    {
      "name": "05 — Delivery lifecycle (optional capability)",
      "description": "These resolver operations require the `delivery_lifecycle` capability and a resolver key with `deliveries:update`. They report privacy-safe shipping status and never return the address.",
      "item": [
        {
          "name": "Get delivery lifecycle",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Lifecycle is returned or capability-gated', () => pm.expect([200, 404, 503]).to.include(pm.response.code));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{delivery_events_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": "{{base_url}}/api/v1/delivery-requests/{{delivery_request_id}}/lifecycle"
          }
        },
        {
          "name": "Record delivery lifecycle event",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Lifecycle event is accepted or capability-gated', () => pm.expect([200, 404, 503]).to.include(pm.response.code));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{delivery_events_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{delivery_event_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"event_id\": \"{{delivery_event_id}}\",\n  \"status\": \"IN_TRANSIT\",\n  \"observed_at\": \"{{$isoTimestamp}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/delivery-requests/{{delivery_request_id}}/events"
          }
        }
      ]
    },
    {
      "name": "99 — Cleanup (optional)",
      "description": "These requests change or revoke active resources. Run them only when the test is complete.",
      "item": [
        {
          "name": "Deactivate webhook subscription",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Webhook is deactivated', () => pm.response.to.have.status(200));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{webhook_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{webhook_deactivate_idempotency_key}}"
              }
            ],
            "url": "{{base_url}}/api/v1/webhooks/{{webhook_id}}/deactivate?organization_id={{organization_id}}"
          }
        },
        {
          "name": "Revoke permission request and descendants",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Permission is revoked or already terminal', () => pm.expect([200, 409]).to.include(pm.response.code));"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{permission_api_key}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{permission_revoke_idempotency_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"reason\": \"Postman integration test completed\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": "{{base_url}}/api/v1/permission-requests/{{permission_request_id}}/revoke",
            "description": "Revokes the permission request and its active descendants, including consent, active tokens, and pending or authorized deliveries."
          }
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "https://addressmask.com",
      "type": "string",
      "description": "AddressMask deployment origin. Do not add a trailing slash."
    },
    {
      "key": "environment",
      "value": "PRODUCTION",
      "type": "string"
    },
    {
      "key": "organization_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "merchant_client_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "resolver_client_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "address_mask",
      "value": "",
      "type": "string"
    },
    {
      "key": "permission_api_key",
      "value": "",
      "type": "string",
      "description": "Merchant key with permission-requests:manage. Store privately."
    },
    {
      "key": "token_api_key",
      "value": "",
      "type": "string",
      "description": "Merchant key with tokens:create. Store privately."
    },
    {
      "key": "resolver_api_key",
      "value": "",
      "type": "string",
      "description": "Resolver key with resolutions:create. Store privately."
    },
    {
      "key": "delivery_events_api_key",
      "value": "",
      "type": "string",
      "description": "Optional resolver key with deliveries:update. Store privately."
    },
    {
      "key": "webhook_api_key",
      "value": "",
      "type": "string",
      "description": "Key with webhooks:manage. Store privately."
    },
    {
      "key": "webhook_endpoint",
      "value": "",
      "type": "string",
      "description": "Public HTTPS endpoint that accepts AddressMask webhook POST requests."
    },
    {
      "key": "request_reason",
      "value": "Deliver Postman integration test order",
      "type": "string"
    },
    {
      "key": "token_ttl_seconds",
      "value": "300",
      "type": "string"
    },
    {
      "key": "workflow_run_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "shipment_ref",
      "value": "",
      "type": "string"
    },
    {
      "key": "permission_expires_at",
      "value": "",
      "type": "string"
    },
    {
      "key": "permission_request_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "policy_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "delivery_request_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "token_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "access_token",
      "value": "",
      "type": "string",
      "description": "Ephemeral one-use access token captured from token issuance. Do not share or persist outside this test."
    },
    {
      "key": "token_expires_at",
      "value": "",
      "type": "string"
    },
    {
      "key": "resolution_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_signing_secret",
      "value": "",
      "type": "string",
      "description": "Returned once when a webhook is created or rotated. Move it to a real secret manager."
    },
    {
      "key": "webhook_delivery_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "last_request_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "permission_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "delivery_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "token_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "resolution_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "resolution_replay_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_replay_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_rotate_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_deactivate_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "delivery_event_idempotency_key",
      "value": "",
      "type": "string"
    },
    {
      "key": "delivery_event_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "permission_revoke_idempotency_key",
      "value": "",
      "type": "string"
    }
  ]
}
