{
  "info": {
    "name": "Affiliate Aggregator — Merchant API (v1)",
    "description": "Signed merchant API (API key + HMAC-SHA256). Set the collection variables base_url, api_key and api_secret (use TEST values). The collection-level pre-request script computes X-Timestamp and X-Signature for every request. The signing secret is shown only once at key creation and is NEVER sent in a request.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "base_url", "value": "http://localhost:4100/api" },
    { "key": "api_key", "value": "ak_test_example" },
    { "key": "api_secret", "value": "sk_test_example_secret" }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Compute HMAC auth headers over `${timestamp}.${rawBody}`.",
          "const ts = Math.floor(Date.now() / 1000).toString();",
          "const body = (pm.request.body && pm.request.body.raw) ? pm.request.body.raw : '';",
          "const secret = pm.collectionVariables.get('api_secret') || pm.environment.get('api_secret');",
          "const sig = CryptoJS.HmacSHA256(ts + '.' + body, secret).toString(CryptoJS.enc.Hex);",
          "pm.variables.set('ts', ts);",
          "pm.variables.set('sig', sig);",
          "pm.variables.set('reqid', (pm.variables.replaceIn('{{$guid}}')));"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Products",
      "item": [
        {
          "name": "Import products",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-Request-ID", "value": "{{reqid}}" },
              { "key": "X-Idempotency-Key", "value": "import-sku-100-2026-06-14" }
            ],
            "body": { "mode": "raw", "raw": "{\"products\":[{\"externalProductId\":\"SKU-100\",\"name\":\"Wireless Earbuds\",\"productUrl\":\"https://merchant-store.com/p/sku-100\",\"price\":\"2999.00\",\"currency\":\"NPR\",\"commissionType\":\"PERCENTAGE\",\"commissionValue\":\"10\"}]}" },
            "url": { "raw": "{{base_url}}/v1/products/import", "host": ["{{base_url}}"], "path": ["v1", "products", "import"] }
          },
          "response": [{ "name": "202 Accepted", "code": 202, "body": "{\n  \"received\": 1,\n  \"created\": 1,\n  \"updated\": 0,\n  \"failed\": 0\n}" }]
        },
        {
          "name": "Upsert products",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-Idempotency-Key", "value": "upsert-sku-100-2026-06-14" }
            ],
            "body": { "mode": "raw", "raw": "{\"products\":[{\"externalProductId\":\"SKU-100\",\"name\":\"Wireless Earbuds v2\",\"productUrl\":\"https://merchant-store.com/p/sku-100\",\"price\":\"2799.00\"}]}" },
            "url": { "raw": "{{base_url}}/v1/products/upsert", "host": ["{{base_url}}"], "path": ["v1", "products", "upsert"] }
          }
        }
      ]
    },
    {
      "name": "Campaigns",
      "item": [
        {
          "name": "Create campaign",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-Idempotency-Key", "value": "campaign-dashain-2026" }
            ],
            "body": { "mode": "raw", "raw": "{\"title\":\"Dashain Sale\",\"defaultCommissionType\":\"PERCENTAGE\",\"defaultCommissionValue\":\"12\",\"cookieDurationDays\":30,\"approvalRequired\":false}" },
            "url": { "raw": "{{base_url}}/v1/campaigns", "host": ["{{base_url}}"], "path": ["v1", "campaigns"] }
          },
          "response": [{ "name": "201 Created", "code": 201, "body": "{\n  \"id\": \"uuid\",\n  \"campaignCode\": \"CMP-AB12CD\",\n  \"title\": \"Dashain Sale\",\n  \"status\": \"DRAFT\"\n}" }]
        }
      ]
    },
    {
      "name": "Conversions",
      "item": [
        {
          "name": "Report conversion",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-Idempotency-Key", "value": "ORD-1001-conversion" }
            ],
            "body": { "mode": "raw", "raw": "{\"clickId\":\"CLK_example123\",\"externalOrderId\":\"ORD-1001\",\"externalProductId\":\"SKU-100\",\"orderAmount\":\"2999.00\",\"currency\":\"NPR\",\"orderStatus\":\"confirmed\"}" },
            "url": { "raw": "{{base_url}}/v1/conversions", "host": ["{{base_url}}"], "path": ["v1", "conversions"] }
          },
          "response": [{ "name": "202 Accepted", "code": 202, "body": "{\n  \"eventId\": \"cnvevt_ab12\",\n  \"status\": \"RECEIVED\",\n  \"duplicate\": false\n}" }]
        }
      ]
    },
    {
      "name": "Order Status",
      "item": [
        {
          "name": "Update order status",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-Idempotency-Key", "value": "ORD-1001-delivered" }
            ],
            "body": { "mode": "raw", "raw": "{\"externalOrderId\":\"ORD-1001\",\"status\":\"delivered\"}" },
            "url": { "raw": "{{base_url}}/v1/order-status", "host": ["{{base_url}}"], "path": ["v1", "order-status"] }
          }
        }
      ]
    },
    {
      "name": "Webhooks",
      "item": [
        {
          "name": "order-created",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-External-Event-Id", "value": "evt-ORD-1001-created" }
            ],
            "body": { "mode": "raw", "raw": "{\"click_id\":\"CLK_example123\",\"external_order_id\":\"ORD-1001\",\"order_amount\":\"2999.00\",\"currency\":\"NPR\"}" },
            "url": { "raw": "{{base_url}}/v1/webhooks/order-created", "host": ["{{base_url}}"], "path": ["v1", "webhooks", "order-created"] }
          },
          "response": [{ "name": "202 Accepted", "code": 202, "body": "{\n  \"webhookEventId\": \"wh_3f9c\",\n  \"status\": \"QUEUED\",\n  \"duplicate\": false\n}" }]
        },
        {
          "name": "order-delivered",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-External-Event-Id", "value": "evt-ORD-1001-delivered" }
            ],
            "body": { "mode": "raw", "raw": "{\"external_order_id\":\"ORD-1001\"}" },
            "url": { "raw": "{{base_url}}/v1/webhooks/order-delivered", "host": ["{{base_url}}"], "path": ["v1", "webhooks", "order-delivered"] }
          }
        },
        {
          "name": "order-cancelled",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-API-Key", "value": "{{api_key}}" },
              { "key": "X-Timestamp", "value": "{{ts}}" },
              { "key": "X-Signature", "value": "{{sig}}" },
              { "key": "X-External-Event-Id", "value": "evt-ORD-1001-cancelled" }
            ],
            "body": { "mode": "raw", "raw": "{\"external_order_id\":\"ORD-1001\",\"reason\":\"customer_request\"}" },
            "url": { "raw": "{{base_url}}/v1/webhooks/order-cancelled", "host": ["{{base_url}}"], "path": ["v1", "webhooks", "order-cancelled"] }
          }
        }
      ]
    }
  ]
}
