{
  "info": {
    "_postman_id": "996fa6d3-4308-4e22-b4d5-printstav1",
    "name": "Print STA API v1",
    "description": "Coleção oficial Print STA API v1 — Docs 2.0.27. O base_url ativo é o endpoint Supabase atual. O domínio canônico https://api.print-sta.com.br/v1 já está preparado no projeto e deve virar o padrão após a ativação DNS/Netlify.",
    "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://bryzmdvfbowtljycefbs.supabase.co/functions/v1",
      "type": "string"
    },
    {
      "key": "canonical_base_url",
      "value": "https://api.print-sta.com.br/v1",
      "type": "string"
    },
    {
      "key": "api_key",
      "value": "pst_test_COLE_SUA_CHAVE",
      "type": "string"
    },
    {
      "key": "account_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "environment",
      "value": "test",
      "type": "string"
    },
    {
      "key": "computer_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "printer_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "job_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_secret",
      "value": "",
      "type": "string"
    },
    {
      "key": "webhook_url",
      "value": "https://example.com/webhooks/print-sta",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "01 — Quickstart",
      "item": [
        {
          "name": "Validar API Key / Conta",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-account",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-account"
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); if (j?.data?.account_id) pm.collectionVariables.set('account_id', j.data.account_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Listar computadores online",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-computers?status=online",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-computers"
              ],
              "query": [
                {
                  "key": "status",
                  "value": "online"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); const x=j?.data?.items?.[0]; if (x?.computer_id) pm.collectionVariables.set('computer_id', x.computer_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Listar impressoras online",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-printers?computer_id={{computer_id}}&status=online",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-printers"
              ],
              "query": [
                {
                  "key": "computer_id",
                  "value": "{{computer_id}}"
                },
                {
                  "key": "status",
                  "value": "online"
                }
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); const x=j?.data?.items?.[0]; if (x?.printer_id) pm.collectionVariables.set('printer_id', x.printer_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Criar primeira impressão TEXT",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "postman-{{$guid}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"printer_id\": \"{{printer_id}}\",\n  \"content\": {\n    \"type\": \"text\",\n    \"encoding\": \"utf8\",\n    \"data\": \"PRINT STA\\\\nPrimeira impressão via Postman\\\\n\"\n  },\n  \"copies\": 1,\n  \"external_id\": \"postman-first-print\",\n  \"title\": \"Primeira impressão Postman\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); if (j?.data?.job_id) pm.collectionVariables.set('job_id', j.data.job_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Consultar job",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs/{{job_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs",
                "{{job_id}}"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "02 — Formatos",
      "item": [
        {
          "name": "Criar job PDF base64",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "pdf-{{$guid}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"printer_id\": \"{{printer_id}}\",\n  \"content\": {\n    \"type\": \"pdf\",\n    \"encoding\": \"base64\",\n    \"data\": \"COLE_AQUI_O_PDF_EM_BASE64\"\n  },\n  \"copies\": 1,\n  \"title\": \"PDF via Postman\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); if (j?.data?.job_id) pm.collectionVariables.set('job_id', j.data.job_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Criar job RAW / ESC-POS",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "raw-{{$guid}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"printer_id\": \"{{printer_id}}\",\n  \"content\": {\n    \"type\": \"raw\",\n    \"encoding\": \"base64\",\n    \"data\": \"G0BQUklOVCBTVEEKCh1WAA==\"\n  },\n  \"copies\": 1,\n  \"title\": \"RAW via Postman\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); if (j?.data?.job_id) pm.collectionVariables.set('job_id', j.data.job_id);"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "03 — Jobs",
      "item": [
        {
          "name": "Listar jobs",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs?limit=25",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "25"
                }
              ]
            }
          }
        },
        {
          "name": "Consultar job atual",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs/{{job_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs",
                "{{job_id}}"
              ]
            }
          }
        },
        {
          "name": "Cancelar job",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs/{{job_id}}/cancel",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs",
                "{{job_id}}",
                "cancel"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"reason\": \"Cancelamento solicitado pelo Postman\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Retry de job",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "retry-{{$guid}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-api-print-jobs/{{job_id}}/retry",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-api-print-jobs",
                "{{job_id}}",
                "retry"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"reason\": \"Retry controlado pelo Postman\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "04 — Webhooks",
      "item": [
        {
          "name": "Listar Webhooks",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/print-sta-list-webhooks?account_public_id={{account_id}}&environment={{environment}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-list-webhooks"
              ],
              "query": [
                {
                  "key": "account_public_id",
                  "value": "{{account_id}}"
                },
                {
                  "key": "environment",
                  "value": "{{environment}}"
                }
              ]
            }
          }
        },
        {
          "name": "Criar Webhook",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-create-webhook",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-create-webhook"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"account_public_id\": \"{{account_id}}\",\n  \"environment\": \"{{environment}}\",\n  \"name\": \"Postman endpoint\",\n  \"url\": \"{{webhook_url}}\",\n  \"events\": [\n    \"job.spooler_completed\",\n    \"job.failed\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j=pm.response.json(); if (j?.data?.webhook_id) pm.collectionVariables.set('webhook_id', j.data.webhook_id); if (j?.data?.secret) pm.collectionVariables.set('webhook_secret', j.data.secret);"
                ]
              }
            }
          ]
        },
        {
          "name": "Enviar evento de teste",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/print-sta-test-webhook",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "print-sta-test-webhook"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"account_public_id\": \"{{account_id}}\",\n  \"environment\": \"{{environment}}\",\n  \"webhook_id\": \"{{webhook_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    }
  ]
}
