{
  "info": {
    "_postman_id": "msgx-api-v1-collection",
    "name": "MsgX API v1",
    "description": "Complete REST API collection for MsgX (by Pistachio Tech LLP). Authenticate using an API key generated from the MsgX dashboard → Settings → Developer → API Keys.\n\nBase URL: {{baseUrl}}\nAPI Key:  {{apiKey}}\n\nAll requests require the header: X-API-Key: {{apiKey}}",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.msgx.app",
      "description": "MsgX API base URL. Change to http://localhost:5001/api for local development."
    },
    {
      "key": "apiKey",
      "value": "wap_YOUR_API_KEY_HERE",
      "description": "Your MsgX API key. Generate one from Dashboard → Settings → Developer → API Keys."
    },
    {
      "key": "toPhone",
      "value": "+919998571057",
      "description": "Recipient WhatsApp number in E.164 format (e.g. +919998571057)"
    },
    {
      "key": "templateName",
      "value": "hello_world",
      "description": "An APPROVED template name from your Meta WABA account"
    },
    {
      "key": "templateLanguage",
      "value": "en_US",
      "description": "Language code for the template"
    },
    {
      "key": "contactId",
      "value": "",
      "description": "Contact ID returned by POST /v1/contacts or GET /v1/contacts"
    }
  ],
  "auth": {
    "type": "apikey",
    "apikey": [
      { "key": "key", "value": "X-API-Key", "type": "string" },
      { "key": "value", "value": "{{apiKey}}", "type": "string" },
      { "key": "in", "value": "header", "type": "string" }
    ]
  },
  "item": [
    {
      "name": "Account",
      "item": [
        {
          "name": "Get Account Info",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/account",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "account"]
            },
            "description": "Returns your account details including business name, plan, and WhatsApp Business Account (WABA) configuration."
          },
          "response": [
            {
              "name": "200 OK",
              "status": "OK",
              "code": 200,
              "body": "{\n  \"id\": \"ten_abc123\",\n  \"businessName\": \"Acme Corp\",\n  \"email\": \"admin@acme.com\",\n  \"phone\": \"+919998571057\",\n  \"wabaId\": \"123456789\",\n  \"phoneNumberId\": \"987654321\",\n  \"plan\": \"FREE\",\n  \"createdAt\": \"2025-04-26T10:00:00.000Z\"\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "Messages",
      "item": [
        {
          "name": "Send Text Message",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"type\": \"text\",\n  \"to\": \"{{toPhone}}\",\n  \"text\": \"Hello from MsgX! 👋 This is a test message sent via the REST API.\"\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/v1/messages/send",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "messages", "send"]
            },
            "description": "Send a free-form text message. NOTE: Only works within the 24-hour customer service window (i.e., after the recipient has messaged you first). For outbound without a prior conversation, use a template message."
          },
          "response": [
            {
              "name": "200 OK",
              "status": "OK",
              "code": 200,
              "body": "{\n  \"success\": true,\n  \"messageId\": \"msg_XkQ9pL2mNv\",\n  \"waMessageId\": \"wamid.XXXXXXXXXXXX\",\n  \"status\": \"SENT\"\n}"
            }
          ]
        },
        {
          "name": "Send Template Message",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"type\": \"template\",\n  \"to\": \"{{toPhone}}\",\n  \"templateName\": \"{{templateName}}\",\n  \"language\": \"{{templateLanguage}}\",\n  \"components\": []\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/v1/messages/send",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "messages", "send"]
            },
            "description": "Send an approved WhatsApp template message. Templates can be sent at any time, even outside the 24-hour window. Use `components` to pass variable values for templates with placeholders."
          },
          "response": [
            {
              "name": "200 OK",
              "status": "OK",
              "code": 200,
              "body": "{\n  \"success\": true,\n  \"messageId\": \"msg_Yw3rT8xNpQ\",\n  \"waMessageId\": \"wamid.XXXXXXXXXXXX\",\n  \"status\": \"SENT\"\n}"
            }
          ]
        },
        {
          "name": "Send Template with Variables",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"type\": \"template\",\n  \"to\": \"{{toPhone}}\",\n  \"templateName\": \"order_confirmation\",\n  \"language\": \"en_US\",\n  \"components\": [\n    {\n      \"type\": \"body\",\n      \"parameters\": [\n        { \"type\": \"text\", \"text\": \"John\" },\n        { \"type\": \"text\", \"text\": \"ORD-20251234\" },\n        { \"type\": \"text\", \"text\": \"₹1,499\" }\n      ]\n    }\n  ]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/v1/messages/send",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "messages", "send"]
            },
            "description": "Send a template with body variables. The `parameters` array maps to {{1}}, {{2}}, {{3}} placeholders in your template body in order."
          }
        }
      ]
    },
    {
      "name": "Contacts",
      "item": [
        {
          "name": "List Contacts",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/contacts?page=1&limit=20&search=",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "contacts"],
              "query": [
                { "key": "page", "value": "1", "description": "Page number (default 1)" },
                { "key": "limit", "value": "20", "description": "Results per page (max 100)" },
                { "key": "search", "value": "", "description": "Search by name or phone number" }
              ]
            },
            "description": "Returns a paginated list of your contacts."
          },
          "response": [
            {
              "name": "200 OK",
              "status": "OK",
              "code": 200,
              "body": "{\n  \"data\": [\n    {\n      \"id\": \"con_Lm7qPw2xNt\",\n      \"name\": \"Chirag Patel\",\n      \"phone\": \"+919998571057\",\n      \"email\": \"chirag@acme.com\",\n      \"tags\": [\"vip\", \"india\"],\n      \"createdAt\": \"2025-04-26T10:00:00.000Z\"\n    }\n  ],\n  \"pagination\": {\n    \"page\": 1,\n    \"limit\": 20,\n    \"total\": 1,\n    \"pages\": 1\n  }\n}"
            }
          ]
        },
        {
          "name": "Create Contact",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Chirag Patel\",\n  \"phone\": \"{{toPhone}}\",\n  \"email\": \"chirag@example.com\",\n  \"tags\": [\"lead\", \"india\"]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{baseUrl}}/v1/contacts",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "contacts"]
            },
            "description": "Create a new contact. Phone must be in E.164 format. Duplicate phones are rejected."
          },
          "response": [
            {
              "name": "201 Created",
              "status": "Created",
              "code": 201,
              "body": "{\n  \"id\": \"con_Lm7qPw2xNt\",\n  \"name\": \"Chirag Patel\",\n  \"phone\": \"+919998571057\",\n  \"email\": \"chirag@example.com\",\n  \"tags\": [\"lead\", \"india\"],\n  \"createdAt\": \"2025-04-26T10:00:00.000Z\"\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "Templates",
      "item": [
        {
          "name": "List Approved Templates",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/templates",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "templates"]
            },
            "description": "Returns all APPROVED WhatsApp message templates linked to your account. Only APPROVED templates can be used to send messages."
          },
          "response": [
            {
              "name": "200 OK",
              "status": "OK",
              "code": 200,
              "body": "{\n  \"data\": [\n    {\n      \"id\": \"tpl_Rp9sQm3kXv\",\n      \"name\": \"hello_world\",\n      \"language\": \"en_US\",\n      \"category\": \"UTILITY\",\n      \"status\": \"APPROVED\",\n      \"body\": \"Hello {{1}}! Welcome to our service.\"\n    }\n  ]\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "Conversations",
      "item": [
        {
          "name": "List Conversations",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/conversations?page=1&limit=20",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "conversations"],
              "query": [
                { "key": "page", "value": "1" },
                { "key": "limit", "value": "20" }
              ]
            },
            "description": "Returns a paginated list of conversations ordered by most recent message."
          }
        }
      ]
    }
  ]
}
