Basely API
Referência da API
Uma chave por negócio. Leia os livros, as contas do banco, as transações, as faturas e as contas a pagar de um negócio, escreva neles com a permissão do dono e receba webhooks assinados quando algo muda.
Começo rápido
- O dono do negócio abre API no painel da Basely e cria uma chave com os scopes que o seu sistema precisa.
- Guarde a chave no ambiente do seu servidor. Ela aparece uma vez só.
- Chame /v1/me para testar a conexão e depois os endpoints que precisar.
curl https://api.baselyapp.com/v1/me \ -H "Authorization: Bearer bsk_live_..." curl "https://api.baselyapp.com/v1/financial/summary?period=2026-09" \ -H "Authorization: Bearer bsk_live_..."
Autenticação
Mande a chave como Authorization: Bearer bsk_live_... em toda requisição.
- O negócio sai da chave. Não existe id de negócio no pedido, e uma chave nunca alcança outro negócio.
- Chaves de teste (bsk_test_) leem o negócio de verdade e validam escritas, mas nunca gravam.
- Só o dono do negócio cria, gira e revoga chaves. A chave para de funcionar quando quem a criou deixa de ser dono.
- Girar mantém a chave antiga funcionando pelo prazo que você escolher, para o servidor trocar sem cair.
- O dono recebe um e-mail toda vez que uma chave nova é criada ou girada.
Scopes
Cada chave leva só os scopes que recebeu. Endpoint sem o scope responde 403 SCOPE_DENIED.
| Scope | Serviço | Acesso |
|---|---|---|
| financial:read | financial | Lê |
| accounts:read | financial | Lê |
| transactions:read | financial | Lê |
| transactions:write | financial | Escreve nos livros |
| invoices:read | financial | Lê |
| invoices:write | financial | Escreve nos livros |
| bills:read | financial | Lê |
| bills:write | financial | Escreve nos livros |
| contacts:read | crm | Lê |
| contacts:write | crm | Escreve |
| crm:read | crm | Lê |
| crm:write | crm | Escreve |
| conversations:read | phone | Lê |
| texts:send | phone | Escreve |
| inbox:write | phone | Escreve |
| calls:create | phone | Escreve |
| sessions:manage | phone | Escreve |
| otp:send | phone | Escreve |
| phone_contacts:write | phone | Escreve |
| bank:refresh | banking | Em breve |
| email:send | Escreve | |
| email:read | Lê | |
| email_templates:write | Escreve | |
| mailboxes:read | Lê | |
| mailboxes:write | Escreve | |
| sms:send | sms | Escreve |
| sms:read | sms | Lê |
| receptionist:read | receptionist | Lê |
| receptionist:write | receptionist | Escreve |
| receptionist:sessions | receptionist | Escreve |
| social:read | social | Lê |
| social:write | social | Escreve |
| funnels:read | funnels | Lê |
| automations:read | automations | Lê |
| courses:read | courses | Lê |
| calendar:read | calendar | Em breve |
| calendar:write | calendar | Em breve |
| files:read | files | Em breve |
Endpoints
Base abaixo. Toda resposta tem o cabeçalho x-request-id.
Plataforma
| GET | /v1/me | any key | The business and the key behind this request. |
Financeiro
| GET | /v1/financial/summary | financial:read | Cash, inflows, outflows, expenses, recurring costs, burn and runway for a period. |
| GET | /v1/financial/cash-flow | financial:read | Cash flow month by month: operating, investing and financing. |
| GET | /v1/financial/reports/{report} | financial:read | A financial report: pnl, balance-sheet, expenses-by-category or trial-balance. |
| GET | /v1/accounts | accounts:read | Bank accounts connected to the books, with their ledger balance. |
| GET | /v1/transactions | transactions:read | Bank transactions, newest first. |
| GET | /v1/transactions/{id} | transactions:read | One bank transaction. |
| POST | /v1/transactions/{id}/categorize | transactions:write | Post a bank transaction to a category in the books. |
| GET | /v1/invoices | invoices:read | Invoices, newest first. |
| POST | /v1/invoices | invoices:write | Create an invoice. |
| GET | /v1/invoices/{id} | invoices:read | One invoice, with what is still open. |
| POST | /v1/invoices/{id}/payments | invoices:write | Record a payment received for an invoice. |
| GET | /v1/bills | bills:read | Bills to pay, newest first. |
| POST | /v1/bills | bills:write | Create a bill to pay. |
CRM
| GET | /v1/contacts | contacts:read | Contacts of the business. |
| POST | /v1/contacts | contacts:write | Create a contact, or update the one with the same email or phone. |
| GET | /v1/companies | crm:read | Companies of the business, newest first. Phone masked. Page with created_before. |
| GET | /v1/deals | crm:read | Deals of the business, newest first: stage, value in cents, contact and company. Filter with stage and archived=true. Page with created_before. |
| GET | /v1/pipelines | crm:read | The business's pipelines, each with its stages in order. |
| GET | /v1/tasks | crm:read | Tasks of the business, newest first. status=open (default), done or all. |
| POST | /v1/deals | crm:write | Create a deal: name, and optionally stage, pipeline_id, category, value_cents, currency, contact_id, company_id, expected_close. Requires Idempotency-Key. |
| PATCH | /v1/deals/{id} | crm:write | Update a deal or move it to another stage: name, stage, category, value_cents, contact_id, company_id, expected_close, archived. Moving a stage can start an automation the owner turned on. Requires Idempotency-Key. |
| POST | /v1/companies | crm:write | Create a company: name, and optionally industry, phone, email, address, website, description. Requires Idempotency-Key. |
| POST | /v1/tasks | crm:write | Create a task: text, and optionally type (follow_up, ligar, visita, enviar, outro), due_at, contact_id, deal_id. Requires Idempotency-Key. |
| PATCH | /v1/tasks/{id} | crm:write | Mark a task done or open again: { done }. Requires Idempotency-Key. |
| POST | /v1/email/send | email:send | Send one transactional email from the business's verified domain. Accepts Idempotency-Key. |
| POST | /v1/email/send/batch | email:send | Send up to 100 transactional emails in one call, each with ONE recipient, its own variables and its own idempotency_key. Each message counts 1 in the plan's emails. The answer is per message (207 when some failed). More than 20 identical messages without variables is a campaign (422), and batches are limited to 300 messages per hour per business (429). Attachments go one per call on /v1/email/send. |
| GET | /v1/email/messages | email:read | Emails sent by the business, newest first. |
| GET | /v1/email/messages/{id} | email:read | One email, with its status and delivery events. |
| GET | /v1/email/senders | email:read | The business's sender and whether it can send now. |
| GET | /v1/email/templates | email:read | The business's email templates. |
| POST | /v1/email/templates | email_templates:write | Create a template. A slug that already exists (from the panel, the connector or the API) returns 409 SLUG_EXISTE with its origin; change it with PUT. Variables are {{name}} and are escaped on send. |
| GET | /v1/email/templates/{slug} | email:read | One template. |
| PUT | /v1/email/templates/{slug} | email_templates:write | Update a template, wherever it was created (panel, connector or API). |
| POST | /v1/email/templates/batch | email_templates:write | Create or update up to 50 templates in one call (counts as one request). Each item may set mode: upsert (default), create or update. The answer is per item (207 when some failed); the same batch repeated gives the same result. |
| DELETE | /v1/email/templates/{slug} | email_templates:write | Move a template to the trash for 30 days (restore with POST .../restore). A template used in the last 7 days returns 409 TEMPLATE_IN_USE with last_used_at; repeat with ?confirm=true. |
| POST | /v1/email/templates/{slug}/restore | email_templates:write | Bring a template back from the trash within 30 days. 409 SLUG_EXISTE if the slug was created again meanwhile. |
| POST | /v1/email/templates/{slug}/preview | email_templates:write | Render a saved template with example variables, as it would be sent. Does not send, does not count and fetches nothing. Lists missing_variables. |
| POST | /v1/email/templates/preview | email_templates:write | Render a template that is not saved yet (template: subject, html, text) with example variables. Does not send, save or fetch anything. |
| GET | /v1/mailboxes | mailboxes:read | The business's mailboxes: those on a domain of the business's site, owned by the business owner. |
| GET | /v1/mailboxes/{address} | mailboxes:read | One mailbox, with usage (bytes_used, bytes_max, messages) and two_factor_enabled read live from the mail server (null when it could not be read). A mailbox of another business returns 404. |
| POST | /v1/mailboxes | mailboxes:write | Create a mailbox on a domain of the business's site, within the plan's free mailboxes (above it, 402 with the link to pay in the panel). No password is accepted or returned: a single-use link to set it (24 hours) goes to the account's email. |
| POST | /v1/mailboxes/{address}/password-link | mailboxes:write | Send the account owner a single-use link (24 hours) to set the mailbox password. The password never goes through the API. |
| GET | /v1/mailboxes/{address}/forwarding | mailboxes:read | Forwarding destinations of the mailbox and whether each one is confirmed. |
| PUT | /v1/mailboxes/{address}/forwarding | mailboxes:write | Ask to forward the mailbox to an address. Nothing is forwarded until the owner of the destination confirms by the link we send there; the API cannot confirm. The account owner is notified. |
| DELETE | /v1/mailboxes/{address}/forwarding | mailboxes:write | Stop forwarding to ?destination=. |
| PUT | /v1/mailboxes/{address}/autoresponder | mailboxes:write | Turn the automatic reply on or off, with an optional start and end. One reply per sender every 24 hours. |
| PUT | /v1/mailboxes/{address}/aliases | mailboxes:write | Replace the mailbox aliases (addresses on the same domain that deliver to it). The account owner is notified. |
SMS
| POST | /v1/sms/send | sms:send | Send one transactional text from a business number. Accepts Idempotency-Key. |
| GET | /v1/sms/messages | sms:read | Texts sent by the business, newest first. Recipients are masked. |
| GET | /v1/sms/messages/{id} | sms:read | One text, with its delivery status and segments. |
| GET | /v1/sms/senders | sms:read | The business numbers, with the US A2P registration status and whether each can send now. |
AI Receptionist
| GET | /v1/receptionist/agents | receptionist:read | The business's AI receptionist agents (one in v1), with greeting, hours, languages and powers. |
| GET | /v1/receptionist/agents/{id} | receptionist:read | One agent. |
| PATCH | /v1/receptionist/agents/{id} | receptionist:write | Change the agent: name, greeting, voice, timezone, languages, hours, powers, instructions and knowledge. |
| PUT | /v1/receptionist/agents/{id}/tools | receptionist:write | Replace the set of Basely tools the agent may use. |
| GET | /v1/receptionist/tools | receptionist:read | The Basely tools (enabled or not) and the app tools registered for the agent. |
| GET | /v1/receptionist/app-tools | receptionist:read | Tools of your own system that the receptionist can call. |
| POST | /v1/receptionist/app-tools | receptionist:write | Register (or update by name) a tool of your system. The signing secret is returned once, on creation. |
| DELETE | /v1/receptionist/app-tools/{name} | receptionist:write | Remove a registered app tool. |
| GET | /v1/receptionist/numbers | receptionist:read | The numbers the receptionist answers, with channels and the US SMS registration. |
| GET | /v1/receptionist/sessions | receptionist:read | Calls and text conversations the receptionist handled, newest first. |
| POST | /v1/receptionist/sessions | receptionist:sessions | Talk to the receptionist from your site or app chat (channel web): send the visitor's message, get the reply. |
| POST | /v1/receptionist/sessions/{id}/handoff | receptionist:sessions | Hand a conversation to the team: the receptionist stops answering this contact for 24 hours and the owner is notified. |
| GET | /v1/receptionist/sessions/{id} | receptionist:read | One session, with transcript, summary, outcome and measured cost. |
| GET | /v1/receptionist/usage | receptionist:read | Usage this month: the receptionist's own cost by part, and the texts and emails it started. |
Redes sociais
| GET | /v1/social/accounts | social:read | The social accounts connected to the business (Instagram, Facebook...). |
| GET | /v1/social/automations | social:read | The automations the owner set up in Social > Plugs, with the photo slots and variables of each template. |
| POST | /v1/social/media | social:write | Store a photo in the business library, from an https URL or the raw image body. Returns a media id. |
| POST | /v1/social/posts | social:write | Post through an automation: send the photos and variables; the template and caption the owner accepted go out on their own. Accepts Idempotency-Key. |
| GET | /v1/social/posts | social:read | Posts requested through the API, newest first, rejections included. |
| GET | /v1/social/posts/{id} | social:read | One post, with its status and the links once it is published. |
Funis
| GET | /v1/funnels | funnels:read | The business's funnels: status, number of steps and when they were published. |
| GET | /v1/funnels/submissions | funnels:read | Form submissions from the funnels, newest first: the answers, consent, and the contact and deal they created. Filter with funnel_id or form_id. Personal data: the visitor's IP is never returned. |
Automações
| GET | /v1/automations | automations:read | The business's automations: enabled, published, trigger type, number of steps and how many contacts are in them. |
| GET | /v1/automations/{id}/runs | automations:read | Runs of one automation, newest first, each with its steps and results. status=active, done, failed, waiting_approval or left. |
Cursos
| GET | /v1/courses | courses:read | The business's courses with their status and number of students. |
| GET | /v1/courses/{id}/students | courses:read | Students of one course with their progress and certificate. |
Phone e textos
| GET | /v1/businesses/{negocioId}/conversations | conversations:read | Messages and calls, masked. |
| POST | /v1/businesses/{negocioId}/texts | texts:send | Send a text from the business number. |
| POST | /v1/businesses/{negocioId}/emails | inbox:write | Hand a received email to the inbox. |
| POST | /v1/businesses/{negocioId}/calls | calls:create | Ring a team member. |
| POST | /v1/businesses/{negocioId}/contacts | phone_contacts:write | Declare a customer or a team member. |
| POST | /v1/businesses/{negocioId}/sessions | sessions:manage | Open a masked line. |
| DELETE | /v1/businesses/{negocioId}/sessions/{sessionId} | sessions:manage | Close a masked line. |
| POST | /v1/businesses/{negocioId}/otp | otp:send | Send a one-time code by text. |
| POST | /v1/businesses/{negocioId}/otp/verify | otp:send | Verify a one-time code. |
Convenções
- Dinheiro em centavos inteiros com a moeda. Datas em ISO 8601.
- Listas devolvem object: list, data, has_more. Use limit (até 100) e from/to para filtrar.
- Os saldos vêm dos livros, que o banco mantém em dia sozinho. Ler nunca pergunta ao banco direto.
- Atualizar agora no banco (Fresh) é uma ação separada, com cota mensal própria. Ler a API nunca gasta Fresh.
- Limite por chave por minuto: 120 leituras, 30 escritas, 20 relatórios. Passou: 429 com retry-after.
- Além do limite por chave, o negócio inteiro tem um teto somando as chaves dele: 300 leituras e 60 escritas por minuto (BUSINESS_RATE_LIMITED).
- Toda escrita aceita o cabeçalho Idempotency-Key. Repetir com a mesma chave e o mesmo pedido devolve a resposta guardada, com Idempotent-Replayed: true, por 24 horas; com outro pedido, 409 IDEMPOTENCY_KEY_REUSED.
- A API lê e escreve no negócio. O que envia em nome dele (e-mail, SMS, código, post pela automação) só passa com o scope que o dono marcou. Cobrar, reembolsar, mudar preço e comprar nunca passam pela API.
Erros
O erro tem um código estável, uma mensagem para gente e o id da requisição. Erro de escrita traz reason e field.
{ "error": { "code": "SCOPE_DENIED", "message": "...", "scope": "invoices:write", "request_id": "req_..." } }| LEVEL_NOT_ALLOWED | This action is not available through the API. Do it in the dashboard. |
| BUSINESS_RATE_LIMITED | Too many requests for this business across all its keys. Retry after the time in Retry-After. |
| IDEMPOTENCY_KEY_INVALID | Idempotency-Key must be 1 to 255 printable ASCII characters. |
| IDEMPOTENCY_KEY_REQUIRED | This write needs an Idempotency-Key header. Send a new one per action and repeat it on retries. |
| MISSING_KEY | Send your API key as Authorization: Bearer <key>. |
| INVALID_KEY | This API key is not valid. |
| KEY_REVOKED | This API key was revoked or replaced. Use the current key of this business. |
| KEY_EXPIRED | This API key expired. Ask the owner of the business for a new one. |
| NOT_FOUND | Not found. |
| BUSINESS_FROZEN | This business is frozen. Calls resume when it is active again. |
| BUSINESS_CLOSED | This business is closed. |
| SCOPE_DENIED | This key does not have the scope this endpoint needs. |
| AFFILIATE_ONLY_ACCOUNT | This key belongs to an affiliate-only account, which cannot use the API. |
| MODULE_NOT_ENABLED | Finance is not enabled for this business. |
| BOOKS_NOT_SET_UP | The books of this business are not set up yet. |
| RATE_LIMITED | Too many requests for this key. Wait and try again. |
| INVALID_REQUEST | The request is not valid. |
| INVALID_JSON | The body must be a JSON object. |
| TEST_MODE | Test keys validate writes but never save them. |
| CONFLICT | The books do not allow this change right now. See reason. |
| FORBIDDEN | The owner of this key can no longer do this in the business. |
| NO_SENDER | This business has no sender for this channel yet. |
| SENDER_NOT_REGISTERED | This number is not registered with the carriers for business texting yet (A2P 10DLC). Finish the registration in Phone > Number. |
| SENDER_NOT_VERIFIED | The sender domain of this business is not verified yet. |
| SENDER_PAUSED | Sending is paused for this business. See the reason in the panel. |
| SYSTEM_SENDER_ONLY_FOR_SYSTEM | The system sender only sends system messages. |
| RECIPIENT_OPTED_OUT | This recipient opted out of texts from this business. |
| RECIPIENT_SUPPRESSED | This address bounced or complained before; sending is blocked. |
| RECIPIENT_REJECTED | The provider rejected this recipient. |
| RECIPIENT_NOT_FOUND | No contact with this id or external id in this business. |
| TETO_GLOBAL_DE_SMS | Texting is paused for the whole platform right now (daily limit). Try again later. |
| DESTINO_FORA_DA_ZONA | This number is outside the dialing zone of the business number. Texts and calls stay within the same country (US and Canada for +1). |
| INVALID_RECIPIENT | The recipient is not a valid phone number in E.164 format. |
| EMPTY_BODY | The message body is empty. |
| QUOTA_EXCEEDED | The quota of this business for this service is used up. |
| PROVIDER_UNAVAILABLE | The delivery provider is unavailable. Try again later with the same Idempotency-Key. |
| IDEMPOTENCY_KEY_REUSED | This Idempotency-Key was already used with a different request. |
| IDEMPOTENCY_IN_PROGRESS | A request with this Idempotency-Key is still being processed. |
| BULK_NOT_ALLOWED | One recipient per request. Lists are campaigns. |
| CATEGORY_NOT_ALLOWED | This category is not allowed for this service yet. |
| CHANNEL_NOT_AVAILABLE | This channel is not offered. See the hint. |
| RECEPTIONIST_OFF | The receptionist is turned off for this business. |
| PLAN_REQUIRED | The business needs an active Phone plan for the receptionist to answer. |
| BUDGET_REACHED | The receptionist reached this month's spending cap. A person will follow up. |
| TEMPLATE_NOT_FOUND | No template with this slug in this business. |
| TEMPLATE_IN_USE | This template was used in the last 7 days. Repeat with ?confirm=true to move it to the trash anyway (restorable for 30 days). |
| ATTACHMENT_URL_NOT_ALLOWED | Attachments are not fetched from URLs. Send the content in base64 or a storage_id from POST /v1/social/media. |
| ATTACHMENT_NOT_FOUND | No file with this storage_id in this business. |
| ATTACHMENT_TYPE_NOT_ALLOWED | Only PNG, JPEG, GIF, WebP, PDF and .ics files can be attached. The type is read from the content. |
| ATTACHMENT_PDF_ACTIVE_CONTENT | This PDF has JavaScript, a launch action or an embedded file, and cannot be attached. |
| ATTACHMENT_NAME_INVALID | The file name must be up to 120 characters, without line breaks. |
| ATTACHMENT_NAME_MISMATCH | The file name extension does not match its content. |
| ATTACHMENT_TOO_LARGE | Each attachment can have at most 5 MB. |
| ATTACHMENTS_TOO_LARGE | The attachments of one email can have at most 10 MB together. |
| TOO_MANY_ATTACHMENTS | At most 5 attachments per email. |
| TOO_MANY_ITEMS | At most 50 templates per batch. |
| PAYLOAD_TOO_LARGE | The request body is too large (5 MB at most). |
| DUPLICATE_IN_BATCH | The same slug appears twice in this batch. |
| SLUG_EXISTE | A template with this slug already exists in this business (see origin: panel, connector or API). Use PUT /v1/email/templates/{slug} to change it. |
| SEND_FAILED | The message was not accepted for delivery. Do not retry it unchanged. |
| AUTOMATION_NOT_FOUND | No automation with this name in this business. See GET /v1/social/automations. |
| AUTOMATION_OFF | This automation is off. The owner turns it on in Social > Plugs; a change to its template or caption turns it off until accepted again. |
| SOCIAL_PLAN_REQUIRED | The business needs an active Social plan to publish. |
| CONSENT_REQUIRED | Send consent.photo: true and consent.collected_at: the customer must have authorized the photo before it is posted. |
| DAILY_LIMIT_REACHED | This automation reached its daily limit. The owner sets it in Social > Plugs. |
| MISSING_PHOTO | A photo slot of the template has no photo. See field. |
| UNKNOWN_SLOT | This photo slot does not exist in the template. See field. |
| INVALID_PHOTO | The photo must be an https URL or a media id from POST /v1/social/media. |
| PHOTO_UNAVAILABLE | We could not download this photo as a PNG, JPG or WEBP image. See field. |
| PHOTO_TOO_LARGE | Photos go up to 15 MB. |
| MEDIA_NOT_FOUND | No image with this media id in this business. |
| MISSING_VARIABLE | A text variable of the template is missing. See field. |
| UNKNOWN_VARIABLE | This variable does not exist in the template. See field. |
| INVALID_VARIABLE | Variables are up to 30 characters, one line, with no link, @ or #. |
| RENDER_UNAVAILABLE | The artwork could not be rendered right now. Try again later with the same reference. |
| PUBLISH_FAILED | The post was not accepted by the publishing engine. See the post status. |
| PASSWORD_NOT_ACCEPTED | The API never receives a mailbox password. A single-use link to set it goes to the account's email. |
| DOMAIN_NOT_IN_BUSINESS | This domain is not a domain of the business's site. |
| MAILBOX_REQUIRES_PAYMENT | This mailbox is beyond the plan's free mailboxes. Add it in the panel (see cta). |
| PLAN_LOCKED | Creating mailboxes unlocks after the account's first payment (see cta). |
| MAILBOX_EXISTS | A mailbox with this address already exists. |
| MAILBOX_IS_GROUP | This address is a group: it forwards to its members and has no password or login. |
| CONTA_SEM_EMAIL | The account that owns this mailbox has no email to receive the link. |
| SERVICE_UNAVAILABLE | The mail service is not configured right now. Try again later. |
| PROVIDER_FAILED | The mail server did not accept the change. Try again; if it keeps failing, send us the request_id. |
| TOO_MANY_MESSAGES | At most 100 messages per batch. |
| ATTACHMENTS_NOT_IN_BATCH | Emails with attachments are sent one per call on POST /v1/email/send. |
| DUPLICATE_IDEMPOTENCY_KEY | The same idempotency_key appears twice in this batch. |
| BATCH_LOOKS_LIKE_CAMPAIGN | More than 20 messages in this batch have the same content and no variables. That is a campaign: send it from Email marketing, with unsubscribe. |
| BATCH_HOURLY_LIMIT | This business reached the batch limit for the last hour (see limit and used). Try again later or send one per call. |
| INTERNAL | Something failed on our side. Try again; if it keeps failing, send us the request_id. |
Webhooks
O dono cadastra o endereço do seu sistema e escolhe os eventos. A entrega tenta de novo por 24 horas.
Cada entrega vem assinada com o segredo do endereço em basely-signature e traz basely-event-id para você descartar repetição. Confira assim:
import { createHmac, timingSafeEqual } from "node:crypto";
// header: basely-signature: t=<unix seconds>,v1=<hex>
export function isFromBasely(rawBody: string, header: string, secret: string): boolean {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=") as [string, string]));
const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
return fresh && timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ""));
}