{
  "info": {
    "name": "Zentrix Agents API",
    "description": "Use your Zentrix AI agent from your own website, app or CRM.\n\n1. Console -> API & Integrations -> Create API key.\n2. In this collection: Variables -> paste the key into `api_key` (Current value).\n3. Send \"Chat - send a message\".\n\nEach `user_id` is one end user with their own conversation (like a separate WhatsApp number).\nDocs: https://agenticai.lk/developers",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{api_key}}", "type": "string" }]
  },
  "variable": [
    { "key": "base_url", "value": "https://agenticai.lk/v1", "type": "string" },
    { "key": "api_key", "value": "PASTE_YOUR_zk_live_KEY_HERE", "type": "string" },
    { "key": "user_id", "value": "customer-123", "type": "string" }
  ],
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test('No auth error (key OK)', () => pm.expect(pm.response.code).to.not.be.oneOf([401, 403]));",
          "pm.test('Not rate limited', () => pm.expect(pm.response.code).to.not.eql(429));"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Me - check key, plan and usage",
      "request": {
        "method": "GET",
        "url": { "raw": "{{base_url}}/me", "host": ["{{base_url}}"], "path": ["me"] },
        "description": "Which business this key belongs to, the plan, `active` (true/false) and usage. Use it first to test your key."
      },
      "event": [{
        "listen": "test",
        "script": { "type": "text/javascript", "exec": [
          "pm.test('Status 200', () => pm.response.to.have.status(200));",
          "const j = pm.response.json();",
          "pm.test('Plan is active (agent can reply)', () => pm.expect(j.active, 'Plan not active: ' + j.reason).to.eql(true));"
        ]}
      }]
    },
    {
      "name": "Chat - send a message",
      "request": {
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"user_id\": \"{{user_id}}\",\n  \"message\": \"Hi, what packages do you have?\",\n  \"name\": \"Nimal\"\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": { "raw": "{{base_url}}/chat", "host": ["{{base_url}}"], "path": ["chat"] },
        "description": "Send one message from your end user and get the agent's reply.\n\n`status`: ok | human_mode (staff took over, reply is null) | no_reply | plan_limit (see `reason` and `message`)."
      },
      "event": [{
        "listen": "test",
        "script": { "type": "text/javascript", "exec": [
          "pm.test('Status 200', () => pm.response.to.have.status(200));",
          "const j = pm.response.json();",
          "pm.test('Agent replied (status ok)', () => pm.expect(j.status, j.message || j.status).to.eql('ok'));",
          "pm.test('Reply text present', () => pm.expect(j.reply).to.be.a('string').and.not.empty);"
        ]}
      }]
    },
    {
      "name": "Chat - follow-up message",
      "request": {
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"user_id\": \"{{user_id}}\",\n  \"message\": \"How much is it for 2 people?\"\n}",
          "options": { "raw": { "language": "json" } }
        },
        "url": { "raw": "{{base_url}}/chat", "host": ["{{base_url}}"], "path": ["chat"] },
        "description": "Same user_id = same conversation, so the agent remembers the previous message."
      }
    },
    {
      "name": "Conversation history",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/conversations/{{user_id}}/messages?limit=50",
          "host": ["{{base_url}}"], "path": ["conversations", "{{user_id}}", "messages"],
          "query": [{ "key": "limit", "value": "50" }]
        },
        "description": "Messages for one user, oldest first. role: user | assistant | staff (your team's replies)."
      },
      "event": [{
        "listen": "test",
        "script": { "type": "text/javascript", "exec": [
          "pm.test('Status 200', () => pm.response.to.have.status(200));",
          "pm.test('Has messages array', () => pm.expect(pm.response.json().messages).to.be.an('array'));"
        ]}
      }]
    },
    {
      "name": "Reset conversation",
      "request": {
        "method": "POST",
        "url": { "raw": "{{base_url}}/conversations/{{user_id}}/reset", "host": ["{{base_url}}"], "path": ["conversations", "{{user_id}}", "reset"] },
        "description": "Forget this user's chat history and start over."
      }
    },
    {
      "name": "Bookings",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/bookings?status=PENDING&limit=100",
          "host": ["{{base_url}}"], "path": ["bookings"],
          "query": [
            { "key": "status", "value": "PENDING", "description": "PENDING | CONFIRMED | CANCELLED (optional)" },
            { "key": "user_id", "value": "{{user_id}}", "disabled": true, "description": "only this user's bookings (optional)" },
            { "key": "limit", "value": "100" }
          ]
        },
        "description": "Bookings / orders / appointments, newest first. `channel` = api or whatsapp."
      }
    },
    {
      "name": "Leads",
      "request": {
        "method": "GET",
        "url": {
          "raw": "{{base_url}}/leads?limit=100",
          "host": ["{{base_url}}"], "path": ["leads"],
          "query": [{ "key": "limit", "value": "100" }]
        },
        "description": "Interested customers the agent saved for your sales team."
      }
    }
  ]
}
