{
  "info": {
    "name": "WatConnexio — First message",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "List your devices, send one real message, and inspect delivery status. Set your key locally. Send requests consume your allowance. Accepted does not prove delivery. Use a number you control."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api-wat.tryconnexio.com",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "deviceId",
      "value": "",
      "type": "string"
    },
    {
      "key": "recipient",
      "value": "",
      "type": "string"
    },
    {
      "key": "message",
      "value": "Hello from WatConnexio!",
      "type": "string"
    },
    {
      "key": "idempotencyKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "messageId",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "1. List my devices",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/whatsapp/devices"
      }
    },
    {
      "name": "2. Send ONE real message",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{baseUrl}}/whatsapp/send-message",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"deviceId\": \"{{deviceId}}\",\n  \"phone\": \"{{recipient}}\",\n  \"message\": \"{{message}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (!pm.collectionVariables.get('idempotencyKey')) pm.collectionVariables.set('idempotencyKey', pm.variables.replaceIn('{{$guid}}'));",
              "['apiKey','deviceId','recipient'].forEach(name => { if (!pm.variables.get(name)) throw new Error('Set '+name+' before sending.'); });"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('Message accepted (not delivery confirmation)', () => pm.response.to.have.status(201));",
              "if (pm.response.code === 201) { const body = pm.response.json(); if (body.data?.messageId) pm.collectionVariables.set('messageId', body.data.messageId); }"
            ]
          }
        }
      ]
    },
    {
      "name": "3. Check delivery status",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/whatsapp/sessions/{{deviceId}}/messages/{{messageId}}/status"
      }
    }
  ]
}
