API reference
Every route the Closeline API serves, who may call it, and how sign-in, workspaces, permissions, errors, lists and limits work.
For the Full Stack package
Base URL and response format
Every route is served under the /api prefix. Locally the base URL is http://localhost:8000/api. On a server it is your API's address followed by /api, the same value both frontends read from NEXT_PUBLIC_API_BASE_URL (Environment variables). Files are served outside the prefix, at /media.
Request bodies are JSON, except file uploads. Every answer comes in the same envelope:
{
"success": true,
"data": { },
"message": ""
}Money is integer cents in every answer, and in a workspace's revenueTarget both ways: 8000000 is 80,000. Only a deal's value is sent in whole units, on POST and PATCH .../deals and on .../close: 12000 is 12,000. Text kept in two languages (deal names, stage names, activity titles, role names) is { "en": "…", "ar": "…" }.
The health check needs no token:
curl http://localhost:8000/api/health{"success":true,"data":{"status":"ok","database":"up"},"message":""}Until the database answers and holds its tables, it answers 503 with "status":"unavailable" and "database":"down". The Docker image's health check reads it.
Errors
A failure keeps the envelope, with success: false and the HTTP status:
{
"success": false,
"data": null,
"message": "deal_version_conflict",
"errors": { "email": ["…"] }
}| Status | Meaning |
|---|---|
400 | Invalid input; errors lists the messages per field |
401 | Not signed in |
403 | Not allowed: the role lacks the permission, sign-ups are closed, or the workspace's plan does not include the feature (plan_upgrade_required) |
404 | Not found, not a member of the workspace, or someone else's record under an own-records grant |
409 | A conflict, such as a stale deal version |
429 | Too many attempts from one address |
503 | Maintenance mode, for anyone who is not platform staff |
When the API has a sentence for the error (a refused sign-in, a 429, sign-ups closed, maintenance mode, a feature the plan does not include), the message is that sentence in the request's language. A 401, 403 or 404 otherwise answers the general sentence for its status, and any other error answers its code for the client to word: deal_version_conflict, loss_reason_required, expected_close_required, contact_email_exists, last_admin.
Lists and paging
Paged lists (deals in the list and closed views, contacts, companies, activities, projects, the installation's users, staff and settings) take page and limit, at most 100 rows a page, and answer:
{ "data": [ ], "total": 62, "page": 1, "limit": 25, "totalPages": 3 }Unless the caller sorts, or the view has an order of its own, rows come newest updated first. A collection that belongs to one workspace and is shown whole (the board, a deal's timeline, notes and files, members, invitations, roles, stages) answers without paging.
Language
Send Accept-Language: ar for Arabic messages; anything else answers in English. Records kept in two languages carry both whatever the header says, and the client picks one.
Signing in
Sign in
Terminalcurl -X POST http://localhost:8000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"demo@closeline.example","password":"CloselineDemo!2026"}'data.access_tokenis the token, withtoken_typeBearer,expires_in(7dby default,JWT_EXPIRATION) andadmin, the account with its platform access and workspaces.GET /api/auth/meanswers the same account later.Call a workspace route
Workspace routes take the workspace's public id, such as
ws-studio-sales, fromGET /api/workspaces.Terminalcurl http://localhost:8000/api/workspaces/ws-studio-sales/deals -H "Authorization: Bearer YOUR_TOKEN"
- An unknown email and a wrong password both answer
401with the same message. - Ten failed sign-ins from one address within 15 minutes answer
429until the oldest failure is 15 minutes old (RATE_LIMIT_LOGIN). Successful sign-ins are not counted. - While maintenance mode is on, a correct sign-in by an account that is not platform staff answers
503. - Tokens are stateless: signing out is the client forgetting its token.
| Method | Path | Who can call it | What it does |
|---|---|---|---|
POST | /api/auth/login | Anyone | Sign in: email, password |
POST | /api/auth/signup | Anyone | A new account and a workspace of its own, signed in: name, email, password (8 to 128 characters), workspace, and optionally plan (starter, team, scale) and billing (monthly, yearly). 403 while sign-ups are closed |
POST | /api/auth/forgot-password | Anyone | Email a reset link: email, optionally locale, the email's language when the account chose none. Always answers { sent: true } |
POST | /api/auth/reset-password | Anyone | Finish a reset: token, password. A link works once, within an hour |
POST | /api/auth/logout | Anyone | Answers { signedOut: true } |
GET | /api/auth/me | Any signed-in account | The account, its platform access and its workspaces |
PATCH | /api/auth/me | Any signed-in account | Edit firstName, lastName, email, phone |
PATCH | /api/auth/me/preferences | Any signed-in account | theme (system, light, dark), reducedMotion, locale (en, ar), lastWorkspaceId |
PATCH | /api/admins/profile/password | Any signed-in account | Change your own password: current_password, password, password_confirmation |
GET | /api/public-settings | Anyone | maintenanceMode and trialDays |
Workspaces and permissions
Every CRM record belongs to a workspace, and its routes are /api/workspaces/:workspaceId/... with the workspace's public id. Each request checks that the caller is a member (otherwise 404) and holds the permission the route names, plainly or as its own-records variant (otherwise 403).
| Resource | Actions |
|---|---|
deals, contacts, activities, reports, projects | view, create, edit, delete, view-own, edit-own |
ai-assistant, team-members, workspace-settings, roles | view, create, edit, delete |
billing | view, edit |
A permission is <resource>.<action>, such as deals.view. With view-own or edit-own, lists, totals, reports and search hold only the caller's records, and anyone else's answers 404. Admin holds every permission and cannot be edited; a caller grants only what it holds itself, and the last Admin cannot be moved to another role.
Platform permissions are separate and belong to the installation's staff: users.*, admins.*, roles.* and settings.*. The seeded Platform admin role holds all of them; Support reads users, staff, roles and settings.
Each workspace has its own clock: the sample workspace is read on Monday 21 September 2026 08:00 UTC, every other one on the real clock. GET /api/workspaces/:workspaceId answers it as clock.
Workspaces, team and roles
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces | Any signed-in account | The caller's workspaces |
GET | /api/workspaces/:workspaceId | A member of the workspace | The workspace, its plan, clock and settings |
PATCH | /api/workspaces/:workspaceId | Members with workspace-settings.edit | name, website, description, currency, timeZone, locale and revenueTarget, the monthly target in integer cents. Only Admin holds the permission by default |
GET | /api/workspaces/:workspaceId/stages | A member of the workspace | The pipeline stages |
PUT | /api/workspaces/:workspaceId/stages | Members with workspace-settings.edit | Replace the stages; moveTo names where a removed stage's deals go |
GET | /api/workspaces/:workspaceId/members | A member of the workspace | The members with their roles |
PATCH | /api/workspaces/:workspaceId/members/:memberId | Members with roles.edit | Change a member's role |
DELETE | /api/workspaces/:workspaceId/members/:memberId | Members with team-members.delete | Remove a member |
GET | /api/workspaces/:workspaceId/invitations | Members with team-members.view | Pending invitations |
POST | /api/workspaces/:workspaceId/invitations | Members with team-members.create | Invite by email with a role; the link works for seven days |
POST | /api/workspaces/:workspaceId/invitations/:id/resend | Members with team-members.create | Send the invitation again |
DELETE | /api/workspaces/:workspaceId/invitations/:id | Members with team-members.create | Cancel an invitation |
GET | /api/invitations/:token | Anyone | What an invitation link is for |
POST | /api/invitations/:token/accept | Any signed-in account | Join the workspace |
GET | /api/workspaces/:workspaceId/roles | Members with team-members.view | The roles and their grants |
GET | /api/workspaces/:workspaceId/roles/changes | Members with team-members.view | Recent role changes |
POST | /api/workspaces/:workspaceId/roles | Members with roles.create | A new role, on the Scale plan |
PUT | /api/workspaces/:workspaceId/roles/:key | Members with roles.edit | Rename a role or change its grants; a change of grants needs the Team or Scale plan |
DELETE | /api/workspaces/:workspaceId/roles/:key | Members with roles.delete | Delete a custom role |
A workspace that is past due beyond its grace days cannot invite people until a plan is paid.
Deals
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces/:workspaceId/deals | Members with deals.view | The board, by stage. ?view=list for the list with its filters; ?status=won, lost, closed or archived for closed deals |
POST | /api/workspaces/:workspaceId/deals | Members with deals.create | A new deal: name, value (whole units), stage, ownerId, optionally the company, contact, expectedClose, probability, source, priority and a first nextStep |
GET | /api/workspaces/:workspaceId/deals/:id | Members with deals.view | One deal |
PATCH | /api/workspaces/:workspaceId/deals/:id | Members with deals.edit | Edit a deal; a stale version answers 409 |
POST | /api/workspaces/:workspaceId/deals/:id/move | Members with deals.edit | Move to stage; useDefault takes the stage's odds; version guards a stale board |
POST | /api/workspaces/:workspaceId/deals/:id/close | Members with deals.edit | outcome won (with closedOn and value) or lost (with reason) |
POST | /api/workspaces/:workspaceId/deals/:id/archive | Members with deals.delete | Take it off the pipeline |
POST | /api/workspaces/:workspaceId/deals/:id/restore | Members with deals.delete | Bring it back |
POST | /api/workspaces/:workspaceId/deals/:id/link-project | Members with deals.edit and projects.create | Link projectId, or create a new project for it |
GET | /api/workspaces/:workspaceId/deals/:id/timeline | Members with deals.view | The deal's timeline |
GET | /api/workspaces/:workspaceId/deals/:id/notes | Members with deals.view | The deal's notes |
POST | /api/workspaces/:workspaceId/notes | Members with deals.view | A note on a deal (dealId) or a contact (contactId): body, up to 5,000 characters |
GET | /api/workspaces/:workspaceId/deals/:id/files | Members with deals.view | The deal's files |
POST | /api/workspaces/:workspaceId/deals/:id/files | Members with deals.edit | Attach a file (multipart file, up to 10 MB) |
GET | /api/workspaces/:workspaceId/deals/:id/files/:fileId/download | Members with deals.view | Download a file |
Contacts, companies and activities
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces/:workspaceId/companies | Members with contacts.view | The companies |
POST | /api/workspaces/:workspaceId/companies | Members with contacts.create | A new company |
PATCH | /api/workspaces/:workspaceId/companies/:id | Members with contacts.edit | Edit a company |
GET | /api/workspaces/:workspaceId/contacts | Members with contacts.view | The contacts, with search, filters and paging |
GET | /api/workspaces/:workspaceId/contacts/export | Members with contacts.view | The filtered contacts as CSV |
POST | /api/workspaces/:workspaceId/contacts | Members with contacts.create | A new contact; an email already in the workspace answers contact_email_exists |
POST | /api/workspaces/:workspaceId/contacts/bulk | Members with contacts.edit | ids with action assign (with ownerId), archive or restore |
POST | /api/workspaces/:workspaceId/contacts/import/preview | Members with contacts.create | Upload a CSV (multipart file, up to 2 MB and 500 rows); answers the columns, a first mapping and the checked rows |
POST | /api/workspaces/:workspaceId/contacts/import/:importId/map | Members with contacts.create | Change the mapping of fields to columns |
POST | /api/workspaces/:workspaceId/contacts/import/:importId/commit | Members with contacts.create | Write the rows; duplicates skip or update |
GET | /api/workspaces/:workspaceId/contacts/:id | Members with contacts.view | One contact, with their deals, timeline and notes |
PATCH | /api/workspaces/:workspaceId/contacts/:id | Members with contacts.edit | Edit a contact |
GET | /api/workspaces/:workspaceId/activities | Members with activities.view | A week of activities; ?view=list for the paged list |
POST | /api/workspaces/:workspaceId/activities | Members with activities.create | A new activity: title, type (call, meeting, task, email), the deal, contact, owner and times; status: "done" logs one that already happened |
GET | /api/workspaces/:workspaceId/activities/:id | Members with activities.view | One activity |
PATCH | /api/workspaces/:workspaceId/activities/:id | Members with activities.edit | Edit, complete, reopen or reschedule |
DELETE | /api/workspaces/:workspaceId/activities/:id | Members with activities.delete | Remove an activity |
An import is kept for an hour; nothing is written before the commit.
Overview, reports, search and the bell
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces/:workspaceId/overview | Members with deals.view | The overview for ?period=month, quarter or year |
GET | /api/workspaces/:workspaceId/reports | Members with reports.view | The report for ?from= and to= (days) |
GET | /api/workspaces/:workspaceId/reports/export | Members with reports.view | The report as CSV |
GET | /api/workspaces/:workspaceId/reports/closed-deals/export | Members with reports.view | Every won and lost deal the caller may see as CSV, newest close first; from and to narrow it by close date. The Export CSV button on Won & lost deals |
GET | /api/workspaces/:workspaceId/search | A member of the workspace | Deals, contacts and companies for ?q= (two characters or more), within the caller's grants |
GET | /api/workspaces/:workspaceId/notifications | A member of the workspace | What changed since the caller's last look, as their role may see it |
POST | /api/workspaces/:workspaceId/notifications/read | A member of the workspace | Mark them read |
Billing
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces/:workspaceId/billing | Members with billing.view | The plan, its status, the users, the next charge and the plans with their prices and features |
GET | /api/workspaces/:workspaceId/billing/invoices | Members with billing.view | The invoices |
GET | /api/workspaces/:workspaceId/billing/invoices/:invoiceId/download-link | Members with billing.view | A signed link to the invoice's PDF, valid five minutes |
POST | /api/workspaces/:workspaceId/billing/preview | Members with billing.edit | What a plan change costs now and at each renewal |
POST | /api/workspaces/:workspaceId/billing/checkout | Members with billing.edit | Start a payment or a plan change; answers the checkout address |
POST | /api/workspaces/:workspaceId/billing/checkout/:sessionId/sync | Members with billing.view | Confirm a returning checkout with the provider |
POST | /api/workspaces/:workspaceId/billing/keep-plan | Members with billing.edit | Take back a change scheduled for the renewal |
POST | /api/workspaces/:workspaceId/billing/portal | Members with billing.edit | Stripe's customer portal address |
POST | /api/workspaces/:workspaceId/billing/cancel | Members with billing.edit | Cancel at the end of the period |
POST | /api/workspaces/:workspaceId/billing/resume | Members with billing.edit | Undo a cancellation |
GET | /api/billing/invoices/download?token= | Anyone with a signed link | The invoice PDF |
POST | /api/billing/webhooks/stripe | Stripe, signed with STRIPE_WEBHOOK_SECRET | Payments, renewals, failed payments and ended subscriptions |
GET | /api/billing/simulator/:sessionId | Any signed-in account | A test checkout session |
POST | /api/billing/simulator/:sessionId/complete | Any signed-in account | Complete the test payment |
POST | /api/billing/simulator/:sessionId/cancel | Any signed-in account | Cancel the test payment |
What each plan includes
Four features depend on the workspace's plan. A request for one the plan does not include answers 403 in the usual envelope, with a stable code, the feature and the smallest plan that has it, and a message in the request's language:
{
"success": false,
"data": { "feature": "customRoles", "plan": "scale" },
"message": "Custom roles are on the Scale plan.",
"code": "plan_upgrade_required"
}| Feature | Plans | Without it |
|---|---|---|
forecast | Team, Scale | GET .../overview and GET .../reports answer every forecast figure as null (forecast, priorForecast, forecastGrowth, each stage's and each owner's forecast), and GET .../reports/export leaves out the forecast lines. Nothing is refused |
assistant | Team, Scale | The assistant's routes answer plan_upgrade_required before any model or record is read |
rolePermissions | Team, Scale | PUT .../roles/:key with permissions answers plan_upgrade_required; a rename without permissions works on every plan |
customRoles | Scale | POST .../roles answers plan_upgrade_required |
- The plan is the workspace's own in every billing state: a trial has the plan it chose, and a past-due, ending or canceled workspace keeps its plan's features. A move to a smaller plan scheduled for the renewal changes nothing until the renewal.
- A smaller plan deletes nothing: custom roles stay assigned, their grants keep working, and they can still be deleted.
GET /api/workspaces/:workspaceIdanswers what the plan includes asplan.featuresand the smallest plan with each feature asplan.featurePlans;GET .../billinggives each plan itsfeatures.- The checks are in the services that do the work (
PlanGateService), so the dashboard, the assistant and the MCP tools meet the same one.
Projects and tasks
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/workspaces/:workspaceId/projects | Members with projects.view | The projects, paged |
GET | /api/workspaces/:workspaceId/projects/archived | Members with projects.view | The archived projects |
GET | /api/workspaces/:workspaceId/projects/owners | Members with projects.view | Who can own a project |
POST | /api/workspaces/:workspaceId/projects | Members with projects.create | A new project |
GET | /api/workspaces/:workspaceId/projects/:projectId | Members with projects.view | One project |
PATCH | /api/workspaces/:workspaceId/projects/:projectId | Members with projects.edit | Edit a project |
DELETE | /api/workspaces/:workspaceId/projects/:projectId | Members with projects.delete | Archive a project |
POST | /api/workspaces/:workspaceId/projects/:projectId/restore | Members with projects.delete | Restore it |
GET | /api/workspaces/:workspaceId/projects/:projectId/activity | Members with projects.view | The project's history |
GET | /api/workspaces/:workspaceId/projects/:projectId/tasks | Members with projects.view | Its tasks |
POST | /api/workspaces/:workspaceId/projects/:projectId/tasks | Members with projects.edit | A new task |
PATCH | /api/workspaces/:workspaceId/tasks/:taskId | Members with projects.edit | Edit a task |
POST | /api/workspaces/:workspaceId/tasks/:taskId/move | Members with projects.edit | Move a task to another column or position |
DELETE | /api/workspaces/:workspaceId/tasks/:taskId | Members with projects.edit | Remove a task |
GET | /api/workspaces/:workspaceId/projects/:projectId/files | Members with projects.view | Its files |
POST | /api/workspaces/:workspaceId/projects/:projectId/files | Members with projects.edit | Upload a file (multipart file, up to 10 MB) |
GET | /api/workspaces/:workspaceId/projects/:projectId/files/:fileId/download | Members with projects.view | Download a file |
The installation: users, staff, roles and settings
| Method | Path | Who can call it | What it does |
|---|---|---|---|
GET | /api/users | Platform staff with users.view | Every account, with its workspaces and platform role |
GET | /api/users/deleted | Platform staff with users.view | Deleted accounts |
GET | /api/users/statistic | Platform staff with users.view | Counts for the users pages |
GET | /api/users/:username | Platform staff with users.view | One account |
GET | /api/users/deleted/:username | Platform staff with users.view | One deleted account |
POST | /api/users | Platform staff with users.create | Create an account |
PATCH | /api/users/:username | Platform staff with users.update | Edit an account |
PATCH | /api/users/:username/change-password | Platform staff with users.update | Set its password |
DELETE | /api/users/:username | Platform staff with users.delete | Delete it; the only Admin of a workspace is refused |
POST | /api/users/deleted/:username/restore | Platform staff with users.restore | Restore it |
GET | /api/admins | Platform staff with admins.view | The platform staff |
GET | /api/admins/statistics | Platform staff with admins.view | Counts |
GET | /api/admins/:id | Platform staff with admins.view | One staff member |
POST | /api/admins | Platform staff with admins.create | Add a staff account |
PATCH | /api/admins/:id | Platform staff with admins.edit | Edit a staff account |
PATCH | /api/admins/profile | Platform staff with admins.edit | Edit your own staff profile, picture included |
PATCH | /api/admins/:id/roles | Platform staff with admins.assign_roles | Grant platform roles |
DELETE | /api/admins/:id | Platform staff with admins.delete | Remove a staff account |
GET | /api/roles | Platform staff with roles.view | The platform roles |
GET | /api/roles/statistics | Platform staff with roles.view | Counts |
GET | /api/roles/select | Platform staff with roles.view | The roles as options |
GET | /api/roles/permissions | Platform staff with roles.view | Every platform permission |
GET | /api/roles/:id | Platform staff with roles.view | One role |
POST | /api/roles | Platform staff with roles.create | Add a platform role |
PUT | /api/roles/:id | Platform staff with roles.edit | Rename it |
POST | /api/roles/:id/permissions | Platform staff with roles.assign_permissions | Choose its permissions |
DELETE | /api/roles/:id | Platform staff with roles.delete | Delete it |
GET | /api/settings | Platform staff with settings.view | The platform settings |
GET | /api/settings/:key | Platform staff with settings.view | One setting |
PATCH | /api/settings/:key | Platform staff with settings.edit | Change it: { "value": "…" } |
DELETE | /api/settings/:key | Platform staff with settings.edit | Delete it |
The dashboard's users pages use the users routes. The staff, platform roles and settings routes have no page: a Platform admin calls them with their token, and an account's page under Users shows its PATCH /api/admins/:id/roles route.
POST /api/adminstakesfirst_name,last_name,email,passwordandpassword_confirmation;PATCH /api/admins/:idchanges those andphone;PATCH /api/admins/profilechanges your own.PATCH /api/admins/:id/rolestakes{ "role_ids": [2] }, with the ids fromGET /api/roles/select;[]removes every platform role.DELETE /api/admins/:idis refused while the account is the last Admin of a workspace.POST /api/rolestakes{ "name": "Billing desk" }, andPOST /api/roles/:id/permissionsthe full list the role holds afterwards,{ "permissions": ["users.view"] }. A role that an account holds cannot be deleted.- A caller grants only roles and permissions it holds itself.
PATCH /api/settings/:keytakes the value as text, numbers and switches included, and applies to the next request.
The contact form and uploads
| Method | Path | Who can call it | What it does |
|---|---|---|---|
POST | /api/contact | Anyone | The website's contact form: name, email, optional company, message, a one-time clientToken that makes a retry safe, and a hidden website field only bots fill in |
POST | /api/helpers/upload | Any signed-in account | Upload a picture (multipart file, up to 10 MB), with path and the size preset for; answers each stored size's address |
Limits per address
| Route | Limit |
|---|---|
POST /api/auth/login | 10 failed sign-ins per 15 minutes (RATE_LIMIT_LOGIN) |
POST /api/auth/signup | 10 per hour |
POST /api/auth/forgot-password | 5 per 15 minutes |
POST /api/auth/reset-password | 10 per 15 minutes |
POST /api/contact | 5 per hour |
A request over a limit answers 429. The counts live in the API's memory, so a restart clears them. Behind a reverse proxy, set TRUST_PROXY so each visitor is counted on their own address.
The assistant and its conversations
Included with your purchase. Sign in to read, or open it in your download.
The assistant's streaming route, its model list, openers, proposals and the saved conversations.
MCP server
Included with your purchase. Sign in to read, or open it in your download.
The MCP endpoint for coding agents and how it is authorised.
Live permission updates
Included with your purchase. Sign in to read, or open it in your download.
The live connection the dashboard listens on for permission changes, its event and how it is authorised.
Demo mode routes
Included with your purchase. Sign in to read, or open it in your download.
The routes that exist only on a public demo build.