{
  "info": {
    "_postman_id": "8a74d1c2-c3fe-47a1-9164-733ccbb6885c",
    "name": "MandaZap — Usuário Final — Produção",
    "description": "Collection exclusiva para clientes da API MandaZap. Configure clientApiKey antes de usar. Contém somente saúde, dependências, gerenciamento de instâncias, QR Code, status e envio de mensagens.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "serverUrl", "value": "https://api.mandazap.me" },
    { "key": "baseUrl", "value": "{{serverUrl}}/api/v1" },
    { "key": "clientApiKey", "value": "" },
    { "key": "instanceName", "value": "principal" },
    { "key": "instanceId", "value": "" },
    { "key": "connectedWhatsAppNumber", "value": "" },
    { "key": "phone", "value": "5517999999999" },
    { "key": "messageText", "value": "Mensagem de teste enviada pela API MandaZap." },
    { "key": "publicImageUrl", "value": "https://URL-PUBLICA-DA-IMAGEM.jpg" },
    { "key": "publicPdfUrl", "value": "https://URL-PUBLICA-DO-ARQUIVO.pdf" },
    { "key": "publicLinkUrl", "value": "https://mandazap.me" }
  ],
  "item": [
    {
      "name": "01 — Saúde",
      "item": [
        {
          "name": "01 — Saúde da API",
          "request": {
            "method": "GET",
            "url": "{{serverUrl}}/health"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": [
              "pm.test('API disponível', () => pm.response.to.have.status(200));",
              "pm.expect(pm.response.json().status).to.eql('ok');"
            ] }
          }]
        },
        {
          "name": "02 — Saúde das dependências",
          "request": {
            "method": "GET",
            "url": "{{serverUrl}}/health/dependencies"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": [
              "pm.test('Dependências disponíveis', () => pm.response.to.have.status(200));",
              "const body = pm.response.json();",
              "pm.expect(body.dependencies.postgresql).to.eql('ok');",
              "pm.expect(body.dependencies.evolution).to.eql('ok');"
            ] }
          }]
        }
      ]
    },
    {
      "name": "02 — Instâncias",
      "item": [
        {
          "name": "01 — Listar instâncias",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": [
              "pm.test('Instâncias consultadas', () => pm.response.to.have.status(200));",
              "const body = pm.response.json();",
              "const instances = body.instancias || [];",
              "const preferred = instances.find((instance) => instance.padrao) || instances[0];",
              "if (preferred && !pm.collectionVariables.get('instanceId')) pm.collectionVariables.set('instanceId', preferred.id);"
            ] }
          }]
        },
        {
          "name": "02 — Criar instância",
          "request": {
            "method": "POST",
            "header": [
              { "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" },
              { "key": "Content-Type", "value": "application/json", "type": "text" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"nome\": \"{{instanceName}}\"\n}" },
            "url": "{{baseUrl}}/instancias"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": [
              "pm.test('Instância criada', () => pm.response.to.have.status(201));",
              "pm.collectionVariables.set('instanceId', pm.response.json().instancia.id);"
            ] }
          }]
        },
        {
          "name": "03 — Definir instância padrão",
          "description": "Define a instância usada automaticamente quando instanciaId não for enviado nas requisições de mensagens.",
          "request": {
            "method": "POST",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}/padrao"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": [
              "pm.test('Instância definida como padrão', () => pm.response.to.have.status(200));",
              "pm.expect(pm.response.json().instancia.padrao).to.eql(true);"
            ] }
          }]
        },
        {
          "name": "04 — Obter QR Code",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}/qrcode"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('QR Code obtido', () => pm.response.to.have.status(200));"] }
          }]
        },
        {
          "name": "05 — Consultar status",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}/status"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('Status consultado', () => pm.response.to.have.status(200));", "const body = pm.response.json();", "const instance = body.instancia || {};", "if (instance.status === 'CONECTADO') {", "  pm.test('Número do WhatsApp conectado retornado', () => {", "    pm.expect(instance.numeroWhatsApp).to.be.a('string').and.match(/^\\d{10,15}$/);", "  });", "  pm.collectionVariables.set('connectedWhatsAppNumber', instance.numeroWhatsApp);", "}"] }
          }]
        },
        {
          "name": "06 — Desconectar instância",
          "request": {
            "method": "POST",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}/desconectar"
          }
        },
        {
          "name": "07 — Reconectar instância",
          "request": {
            "method": "POST",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}/reconectar"
          }
        },
        {
          "name": "08 — Excluir instância",
          "description": "Atenção: remove a instância selecionada em instanceId.",
          "request": {
            "method": "DELETE",
            "header": [{ "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" }],
            "url": "{{baseUrl}}/instancias/{{instanceId}}"
          }
        }
      ]
    },
    {
      "name": "03 — Mensagens",
      "item": [
        {
          "name": "01 — Enviar texto",
          "request": {
            "method": "POST",
            "header": [
              { "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" },
              { "key": "Idempotency-Key", "value": "texto:{{$guid}}", "type": "text" },
              { "key": "Content-Type", "value": "application/json", "type": "text" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"numero\": \"{{phone}}\",\n  \"mensagem\": \"{{messageText}}\",\n  \"instanciaId\": \"{{instanceId}}\"\n}" },
            "url": "{{baseUrl}}/mensagens/texto"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('Texto processado ou já concluído', () => pm.expect([200, 201]).to.include(pm.response.code));"] }
          }]
        },
        {
          "name": "02 — Enviar imagem por URL",
          "request": {
            "method": "POST",
            "header": [
              { "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" },
              { "key": "Idempotency-Key", "value": "imagem:{{$guid}}", "type": "text" },
              { "key": "Content-Type", "value": "application/json", "type": "text" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"numero\": \"{{phone}}\",\n  \"media\": \"{{publicImageUrl}}\",\n  \"mimetype\": \"image/jpeg\",\n  \"legenda\": \"Imagem enviada pela API MandaZap.\",\n  \"instanciaId\": \"{{instanceId}}\"\n}" },
            "url": "{{baseUrl}}/mensagens/imagem"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('Imagem processada ou já concluída', () => pm.expect([200, 201]).to.include(pm.response.code));"] }
          }]
        },
        {
          "name": "03 — Enviar PDF por URL",
          "request": {
            "method": "POST",
            "header": [
              { "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" },
              { "key": "Idempotency-Key", "value": "pdf:{{$guid}}", "type": "text" },
              { "key": "Content-Type", "value": "application/json", "type": "text" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"numero\": \"{{phone}}\",\n  \"media\": \"{{publicPdfUrl}}\",\n  \"mimetype\": \"application/pdf\",\n  \"nomeArquivo\": \"documento.pdf\",\n  \"legenda\": \"Documento enviado pela API MandaZap.\",\n  \"instanciaId\": \"{{instanceId}}\"\n}" },
            "url": "{{baseUrl}}/mensagens/documento"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('PDF processado ou já concluído', () => pm.expect([200, 201]).to.include(pm.response.code));"] }
          }]
        },
        {
          "name": "04 — Enviar link",
          "request": {
            "method": "POST",
            "header": [
              { "key": "X-API-Key", "value": "{{clientApiKey}}", "type": "text" },
              { "key": "Idempotency-Key", "value": "link:{{$guid}}", "type": "text" },
              { "key": "Content-Type", "value": "application/json", "type": "text" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"numero\": \"{{phone}}\",\n  \"link\": \"{{publicLinkUrl}}\",\n  \"mensagem\": \"Acesse o link.\",\n  \"instanciaId\": \"{{instanceId}}\"\n}" },
            "url": "{{baseUrl}}/mensagens/link"
          },
          "event": [{
            "listen": "test",
            "script": { "exec": ["pm.test('Link processado ou já concluído', () => pm.expect([200, 201]).to.include(pm.response.code));"] }
          }]
        }
      ]
    }
  ]
}
