{
  "info": {
    "name": "Digiwhats — User API",
    "description": "API por empresa: conectar canais e enviar mensagens via API key.\n\nConfigure as variáveis da coleção:\n- baseUrl: https://app.digiwhats.com.br/api/v1/company\n- apiKey: a sua chave dwuser_live_… (gerada em Integração API)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "baseUrl", "value": "https://app.digiwhats.com.br/api/v1/company" },
    { "key": "apiKey", "value": "dwuser_live_SUA_CHAVE" },
    { "key": "channelId", "value": "" },
    { "key": "departmentId", "value": "" }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{apiKey}}", "type": "string" }]
  },
  "item": [
    {
      "name": "Canais",
      "item": [
        {
          "name": "Criar canal (não-oficial: whatsmeow/baileys)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/channels", "host": ["{{baseUrl}}"], "path": ["channels"] },
            "body": { "mode": "raw", "raw": "{\n  \"name\": \"API Vendas\",\n  \"provider\": \"whatsmeow\"\n}" }
          }
        },
        {
          "name": "Conectar canal Cloud (API oficial da Meta)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/channels/cloud", "host": ["{{baseUrl}}"], "path": ["channels", "cloud"] },
            "body": { "mode": "raw", "raw": "{\n  \"name\": \"Vendas (Cloud)\",\n  \"phoneNumberId\": \"120376389012345\",\n  \"accessToken\": \"EAAG…\",\n  \"wabaId\": \"1029384756\"\n}" }
          }
        },
        {
          "name": "Listar canais",
          "request": { "method": "GET", "url": { "raw": "{{baseUrl}}/channels", "host": ["{{baseUrl}}"], "path": ["channels"] } }
        },
        {
          "name": "Status do canal",
          "request": { "method": "GET", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}"] } }
        },
        {
          "name": "Conectar (gera QR)",
          "request": { "method": "POST", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/connect", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "connect"] } }
        },
        {
          "name": "Obter QR (string + PNG base64)",
          "request": { "method": "GET", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/qr", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "qr"] } }
        },
        {
          "name": "Parear por código",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/pair-phone", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "pair-phone"] },
            "body": { "mode": "raw", "raw": "{\n  \"phone\": \"5548999998888\"\n}" }
          }
        },
        {
          "name": "Obter código de pareamento",
          "request": { "method": "GET", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/pair-code", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "pair-code"] } }
        },
        {
          "name": "Desconectar",
          "request": { "method": "POST", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/disconnect", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "disconnect"] } }
        },
        {
          "name": "Excluir canal",
          "request": { "method": "DELETE", "url": { "raw": "{{baseUrl}}/channels/{{channelId}}", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}"] } }
        }
      ]
    },
    {
      "name": "Mídia",
      "item": [
        {
          "name": "Upload de mídia",
          "request": {
            "method": "POST",
            "url": { "raw": "{{baseUrl}}/media", "host": ["{{baseUrl}}"], "path": ["media"] },
            "body": { "mode": "formdata", "formdata": [{ "key": "file", "type": "file", "src": [] }] }
          }
        }
      ]
    },
    {
      "name": "Templates (Cloud)",
      "item": [
        {
          "name": "Listar templates — TODOS (com status)",
          "request": {
            "method": "GET",
            "header": [],
            "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/templates", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "templates"] },
            "description": "Devolve todos, inclusive PENDING/REJECTED. Use para acompanhar a aprovação de um template submetido e ler o rejectionReason."
          }
        },
        {
          "name": "Listar templates — só os ENVIÁVEIS",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/channels/{{channelId}}/templates?sendableOnly=true",
              "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "templates"],
              "query": [{ "key": "sendableOnly", "value": "true" }]
            },
            "description": "Só o que dá para enviar agora: status=APPROVED E enabled=true. Evita reimplementar a regra do seu lado."
          }
        },
        {
          "name": "Sincronizar templates da Meta",
          "request": {
            "method": "POST",
            "header": [],
            "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/templates/sync", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "templates", "sync"] },
            "description": "Puxa o estado atual da WABA na Meta e atualiza o cache local — use antes de listar se acabou de aprovar algo no Business Manager."
          }
        },
        {
          "name": "Submeter template para aprovação",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/channels/{{channelId}}/templates", "host": ["{{baseUrl}}"], "path": ["channels", "{{channelId}}", "templates"] },
            "body": { "mode": "raw", "raw": "{\n  \"name\": \"pedido_confirmado\",\n  \"language\": \"pt_BR\",\n  \"category\": \"UTILITY\",\n  \"body\": \"Olá {{1}}, seu pedido {{2}} foi confirmado.\",\n  \"bodyExample\": [[\"João\", \"#4821\"]]\n}" },
            "description": "Nasce PENDING. Acompanhe o status pelo GET acima até virar APPROVED. Atenção: bodyExample é ARRAY DE ARRAYS."
          }
        },
        {
          "name": "INICIAR conversa fora das 24h (enviar template)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/messages", "host": ["{{baseUrl}}"], "path": ["messages"] },
            "body": { "mode": "raw", "raw": "{\n  \"channelId\": \"{{channelId}}\",\n  \"departmentId\": \"{{departmentId}}\",\n  \"to\": \"5548999998888\",\n  \"type\": \"template\",\n  \"template\": {\n    \"name\": \"pedido_confirmado\",\n    \"language\": \"pt_BR\",\n    \"components\": [\n      {\n        \"type\": \"body\",\n        \"parameters\": [\n          { \"type\": \"text\", \"text\": \"João\" },\n          { \"type\": \"text\", \"text\": \"#4821\" }\n        ]\n      }\n    ]\n  }\n}" },
            "description": "Fora da janela de 24h, a API oficial SÓ aceita template aprovado — é assim que se inicia (ou reabre) uma conversa. Dentro das 24h, texto livre funciona normalmente."
          }
        }
      ]
    },
    {
      "name": "Mensagens",
      "item": [
        {
          "name": "Enviar texto",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/messages", "host": ["{{baseUrl}}"], "path": ["messages"] },
            "body": { "mode": "raw", "raw": "{\n  \"channelId\": \"{{channelId}}\",\n  \"departmentId\": \"{{departmentId}}\",\n  \"to\": \"5548999998888\",\n  \"type\": \"text\",\n  \"text\": \"Olá! Seu pedido saiu para entrega.\"\n}" }
          }
        },
        {
          "name": "Enviar imagem",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/messages", "host": ["{{baseUrl}}"], "path": ["messages"] },
            "body": { "mode": "raw", "raw": "{\n  \"channelId\": \"{{channelId}}\",\n  \"departmentId\": \"{{departmentId}}\",\n  \"to\": \"5548999998888\",\n  \"type\": \"image\",\n  \"mediaRef\": \"COLE_A_KEY_DO_UPLOAD\",\n  \"mimeType\": \"image/jpeg\",\n  \"caption\": \"Nota fiscal\"\n}" }
          }
        },
        {
          "name": "Status de entrega",
          "request": { "method": "GET", "url": { "raw": "{{baseUrl}}/messages/COLE_O_MESSAGE_ID", "host": ["{{baseUrl}}"], "path": ["messages", "COLE_O_MESSAGE_ID"] } }
        },
        {
          "name": "Responder mensagem recebida — texto (WhatsApp/Instagram/Telegram)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/messages/COLE_O_MESSAGE_ID/reply", "host": ["{{baseUrl}}"], "path": ["messages", "COLE_O_MESSAGE_ID", "reply"] },
            "body": { "mode": "raw", "raw": "{\n  \"type\": \"text\",\n  \"text\": \"Claro! Já estou verificando por aqui.\"\n}" }
          }
        },
        {
          "name": "Responder mensagem recebida — imagem",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/messages/COLE_O_MESSAGE_ID/reply", "host": ["{{baseUrl}}"], "path": ["messages", "COLE_O_MESSAGE_ID", "reply"] },
            "body": { "mode": "raw", "raw": "{\n  \"type\": \"image\",\n  \"mediaRef\": \"COLE_A_KEY_DO_UPLOAD\",\n  \"mimeType\": \"image/jpeg\",\n  \"caption\": \"Segue o comprovante\"\n}" }
          }
        }
      ]
    }
  ]
}
