API REST v1

API documentation

Catalogue of available REST endpoints. Authentication via Bearer JWT in the Authorization header.

Base URL: https://crm.xpevolution.fr/api/v1

Auth: Authorization: Bearer <jwt-access-token> (obter em /auth/login)

Content-Type: application/json em todos os POSTs/PATCHs

🔐 Auth

POST /auth/register — Cria tenant + admin Public (no auth)
POST /auth/login — Login com slug + email + senha Public (no auth)
POST /auth/refresh — Renova access token Public (no auth)
POST /auth/logout — Logout (auditado) Auth required
GET /me — Usuário autenticado atual Auth required

👥 Users

GET /users — Lista paginada (filtros: q, role, is_active, sort, order, page, per_page) Auth required
POST /users — Criar usuário Min. role: tenant_admin
GET /users/{id:uuid} — Detalhe Auth required
PATCH /users/{id:uuid} — Atualizar (admin: tudo / self: campos limitados) Auth required
DELETE /users/{id:uuid} — Soft delete Min. role: tenant_admin
POST /users/{id:uuid}/restore — Restaurar Min. role: tenant_admin
POST /users/{id:uuid}/password — Trocar senha (self exige current_password) Auth required

🏛️ Accounts (empresas)

GET /accounts — Lista (filtros: q, lifecycle_stage, tier, industry, owner_id, country) Auth required
POST /accounts — Criar Min. role: sales+
GET /accounts/{id:uuid} — Detalhe Auth required
PATCH /accounts/{id:uuid} — Atualizar Min. role: sales+
DELETE /accounts/{id:uuid} — Soft delete Min. role: manager+
POST /accounts/{id:uuid}/restore — Restaurar Min. role: manager+

👤 Contacts (pessoas)

GET /contacts — Lista (filtros: q, lifecycle_stage, lead_status, temperature, account_id, owner_id, do_not_contact) Auth required
POST /contacts — Criar (full_name e dedupe_hash auto-gerados) Min. role: sales+
GET /contacts/{id:uuid} — Detalhe Auth required
PATCH /contacts/{id:uuid} — Atualizar Min. role: sales+
DELETE /contacts/{id:uuid} — Soft delete Min. role: manager+
POST /contacts/{id:uuid}/restore — Restaurar Min. role: manager+

🔄 Pipelines & Stages

GET /pipelines — Listar pipelines Auth required
POST /pipelines — Criar (?seed=true cria 6 stages padrão) Min. role: manager+
GET /pipelines/{id:uuid} — Detalhe c/ stages Auth required
PATCH /pipelines/{id:uuid} — Atualizar Min. role: manager+
DELETE /pipelines/{id:uuid} — Soft delete Min. role: tenant_admin
POST /pipelines/{id:uuid}/restore — Restaurar Min. role: tenant_admin
GET /pipelines/{id:uuid}/stages — Listar stages Auth required
POST /pipelines/{id:uuid}/stages — Criar stage Min. role: manager+
PATCH /pipelines/{id:uuid}/stages/{stageId:uuid} — Atualizar stage Min. role: manager+
DELETE /pipelines/{id:uuid}/stages/{stageId:uuid} — Deletar stage (bloqueia se tem opps) Min. role: manager+

💼 Opportunities (deals)

GET /opportunities — Lista (15+ filtros: status, priority, owner, account, pipeline, stage, faixa de valor, datas) Auth required
POST /opportunities — Criar (FK validation completa) Min. role: sales+
GET /opportunities/{id:uuid} — Detalhe Auth required
PATCH /opportunities/{id:uuid} — Atualizar (stage_id BANIDO — usar /move) Min. role: sales+
DELETE /opportunities/{id:uuid} — Soft delete Min. role: manager+
POST /opportunities/{id:uuid}/restore — Restaurar Min. role: manager+
POST /opportunities/{id:uuid}/move — Mover de stage (auto-detecta won/lost, registra histórico) Min. role: sales+
GET /opportunities/{id:uuid}/history — Timeline de movimentações Auth required

📅 Activities

GET /activities — Lista (filtros: type, status, owner_id=me, opportunity_id, overdue, due_from/to) Auth required
POST /activities — Criar (link polimórfico obrigatório) Min. role: sales+
GET /activities/{id:uuid} — Detalhe Auth required
PATCH /activities/{id:uuid} — Atualizar Min. role: sales+
DELETE /activities/{id:uuid} — Soft delete Min. role: sales+
POST /activities/{id:uuid}/restore — Restaurar Min. role: manager+
POST /activities/{id:uuid}/complete — Atalho: marcar como concluída Min. role: sales+

📊 Dashboard

GET /dashboard/summary — 12 KPIs (contatos, accounts, pipeline aberto, won_this_month, conversion_rate, avg_cycle, activities) Auth required
GET /dashboard/pipeline — Kanban-ready (?pipeline_id=...). Stages com counts e values Auth required
GET /dashboard/activity-feed — Timeline (?limit=20). Joina nomes de owner, contact, account, opp Auth required

Health & Diagnóstico

GET /api/v1/ping — Liveness Public (no auth)
GET /api/v1/health — Readiness (DB + Redis + Meili) Public (no auth)