Rolebase Developers

tRPC API

Call the Rolebase backend procedures (tRPC) that complement the GraphQL API.

Overview

Most data in Rolebase is read and written through the GraphQL API, which is the recommended surface for integrations. Alongside it, the backend exposes a tRPC API: the typed RPC layer that the web app uses for operations that go beyond plain CRUD, such as creating an organization with its seed roles, archiving a circle and its descendants, exporting data, or inviting a member.

This section documents the procedures that are useful from outside the app, one page per router. Internal procedures (webhooks, scheduled jobs, search indexing) are listed for reference and are not meant to be called directly.

Info Circle GraphQL first

For reading and writing entities, prefer the GraphQL API. Reach for tRPC only for the actions below, which encapsulate business logic the GraphQL layer does not expose.

Endpoint

The tRPC API is served at the backend root:

  • Production: https://api.rolebase.io
  • Local development: http://localhost:8888

It speaks the standard tRPC HTTP protocol (queries over GET, mutations over POST), so it works with any tRPC client or with plain HTTP.

Authentication

tRPC procedures are authenticated with an API key, the same key the GraphQL API uses. Create one from Settings > API keys in the app and send it in the x-api-key header:

x-api-key: <your-api-key>

The procedures run with the permissions of the user the key belongs to. A few procedures are public (such as reading an invitation or a shared org), and the internal procedures use a webhook secret instead.

Info Circle Access tokens

The web app authenticates with the Nhost access token of the signed-in user (Authorization: Bearer <token>), which the backend also accepts. Those tokens are short-lived and tied to a browser session, so external integrations should use an API key. Admin-only procedures stay reserved for access tokens carrying the admin role.

Type-safe client

The cleanest way to call the API is a typed tRPC client that imports the router type from the backend package:

import { createTRPCClient, httpBatchLink } from '@trpc/client'
import type { AppRouter } from '@rolebase/backend'
const trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'https://api.rolebase.io',
headers: () => ({
'x-api-key': apiKey,
}),
}),
],
})
// Query
const data = await trpc.org.getPublicData.query({ orgId })
// Mutation
const { id } = await trpc.org.createOrg.mutate({ name: 'Acme', slug: 'acme' })

Raw HTTP

You can also call procedures over plain HTTP without a tRPC client.

Terminal window
# Query: GET /<procedure>?input=<url-encoded-json>
curl 'https://api.rolebase.io/org.getPublicData?input=%7B%22orgId%22%3A%22YOUR_ORG_ID%22%7D' \
-H 'x-api-key: YOUR_API_KEY'
# Mutation: POST /<procedure> with the input as the JSON body
curl -X POST 'https://api.rolebase.io/circle.archiveCircle' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"circleId": "YOUR_CIRCLE_ID"}'

The response is wrapped as { "result": { "data": <value> } }.

Errors

A failed call answers with { "error": { "message": ..., "data": { "code": ..., "httpStatus": ... } } }, and a typed client throws a TRPCClientError carrying the same code. The codes are the same across every procedure, so the reference pages only mention what is specific to a procedure.

CodeStatusMeaning
UNAUTHORIZED401Missing or invalid API key, or a procedure that needs a signed-in user.
FORBIDDEN403The key holder lacks the required role or permission on that entity.
NOT_FOUND404The id does not exist, or is not visible to the key holder.
BAD_REQUEST400Input rejected by the procedure schema, or a state that forbids the action.
INTERNAL_SERVER_ERROR500Unexpected failure, including a rejected call to an external service.

Procedures

Procedures are grouped in routers, and a call combines the router name and the procedure name: org.createOrg, circle.archiveCircle.

RouterProcedures
Organizations (org)Create, export, import, share and archive an organization
Members (member)Invitations, access roles, archive and restore
Roles (circle, proposal)Archive a role with its descendants, resolve a proposal
Meetings (meeting)Video meeting access token
AI and search (ai, search)Role drafts, meeting summaries, scoped search key
Calendar apps (apps)List and select calendars, disconnect an app
Subscriptions (orgSubscription)Stripe billing, invoices and payment methods
Users (user)Check that an email domain receives emails
Internal (cron, trigger, ...)Scheduled jobs and webhooks, listed for reference

Next steps