API REST

Automatize backups e restaurações. Disponível no plano Agência. Crie a chave em Conta e API.

Autenticação

Envie a chave no cabeçalho Authorization: Bearer sk_live_…. Limite: 120 pedidos por minuto por chave. Uma chave pode valer pra todos os sites ou só pra um.

curl https://trendrestore.com.br/api/v1/sites -H "Authorization: Bearer sk_live_SUA_CHAVE"

Listar sites

GET/api/v1/sites
{ "data": [ { "id": "…", "name": "meusite.com.br", "agent": "wordpress", "connected": true,
  "schedule": "0 3 * * *", "strategy": "INCREMENTAL_WEEKLY_FULL", "next_run_at": "…" } ] }

Fazer um backup

POST/api/v1/sites/{site_id}/backups
curl -X POST https://trendrestore.com.br/api/v1/sites/SITE_ID/backups \
  -H "Authorization: Bearer sk_live_SUA_CHAVE" -H "Content-Type: application/json" \
  -d '{"type":"full"}'     # full | incremental | database
202 { "data": { "id": "…", "status": "queued", "type": "full", "progress": 0 } }
409 se já houver um backup em andamento

Listar backups

GET/api/v1/sites/{site_id}/backups?limit=30
{ "data": [ { "id": "…", "type": "incremental", "status": "completed", "size_bytes": 44040192,
  "files": 14212, "changed": 49, "db_tables": 128, "encrypted": false, "finished_at": "…" } ] }

Acompanhar um backup

GET/api/v1/backups/{backup_id}

Status: queued → running → uploading → verifying → completed (ou failed com o motivo em "error").

{ "data": { "id": "…", "status": "uploading", "progress": 72, "step": "Enviando pro seu Google Drive" } }

Restaurar

POST/api/v1/sites/{site_id}/restores

Antes de restaurar, a plataforma faz um backup de segurança do estado atual. Acompanhe em GET /api/v1/restores/{id}.

curl -X POST https://trendrestore.com.br/api/v1/sites/SITE_ID/restores \
  -H "Authorization: Bearer sk_live_SUA_CHAVE" -H "Content-Type: application/json" \
  -d '{"backup_id":"BACKUP_ID","scope":"database"}'     # full | files | database
202 { "data": { "id": "…", "status": "queued", "safety_backup_id": null } }

Webhooks

Eventos: backup.started backup.completed backup.failed restore.completed restore.failed. Até 6 tentativas com espera crescente.

Confira a assinatura: X-TrendRestore-Signature: t=TIMESTAMP,v1=HMAC, onde HMAC = HMAC-SHA256(segredo, "TIMESTAMP.corpo").

// Node.js
const [t, v1] = header.split(",").map((p) => p.split("=")[1]);
const ok = crypto.createHmac("sha256", SEGREDO).update(`${t}.${rawBody}`).digest("hex") === v1;