@sublay/node SDK gives you full programmatic access to the Sublay API from any Node.js environment. It is designed for server-side use only — backend endpoints, Next.js server actions, webhook handlers, cron jobs, and scripts.
This SDK requires a secret API key and must never be used in client-side
code or shipped to the browser.
Installation
Initialization
Create a singleSublayClient instance at startup and reuse it throughout your application.
Configuration
Your secret API key from the dashboard. Keep this in an environment variable —
never commit it to source control.
Modules
Once initialized, all functionality is accessed through module namespaces on the client:Acting on behalf of a user
Your service key authenticates as the project, not as any single end user. So functions that operate on a user’s behalf takeactingUserId: the user the service key acts as (saving to a collection, reading a notification feed, filing a report, listing connections, moderating a space). The request runs with that user’s permissions — their role in a space, their hosting of an event, their membership of a conversation — and is recorded as theirs.
userId only ever names a user the request is about: a target, such as the user to follow, block or add to a conversation, or a filter, such as the author filter on fetchManyEntities. So a call that acts on one user toward another carries both, for example createFollow({ userId: target, actingUserId: actor }).
Where a method requires an acting user and you leave actingUserId out, the server answers 400 <resource>/missing-user-id. An actingUserId that isn’t a user in the project gets 404 <resource>/user-not-found, on every method that takes one. Reads shaped by who is looking (the entities, comments and spaces reads and reaction lists, spaces.fetchSpaceMembers, fetchSpaceTeam, fetchManyRules, fetchRule and fetchSpaceBreadcrumb, the events reads and fetchEventRsvps, reputation.listGrants, the users profile and suggestion reads, the follower, following and connection lists and their counts, users.fetchCommentsByUserId, search.searchUsers, search.searchContent and search.askContent) take it optionally: with it you get exactly that user’s view, without it the anonymous one (for listGrants, that of a signed-in user in no conversation). entities.updateEntity and deleteEntity, comments.updateComment and deleteComment, and storage.deleteFile act as the record’s owner: pass the author as actingUserId when the record has one, and leave it out only for an app-owned record. entities.publishDraft requires actingUserId, the draft’s author: a draft always has one (one without is answered as not found). entities.createEntity and the storage uploads without actingUserId create an app-owned record; a draft needs actingUserId. users.fetchOrCreateUserByForeignId always creates as your app; its optional actingUserId only shapes the user it returns. spaces.deleteSpace and every workspaces function require actingUserId and run with exactly that user’s role or standing. users.updateUser requires actingUserId, and it must be the user being updated: the update behaves exactly as that user’s own token. users.deleteUser, push.send, reputation.mintGrant, entities.incrementEntityViews and the tables table and column functions (createTable, dropTable, addColumn, dropColumn) act as your app and take no actingUserId (the server refuses it with 400 <resource>/unsupported-param). Methods where no user’s view matters, such as users.checkUsernameAvailability, take no actingUserId either; the server ignores one, like any other field it doesn’t use. Endpoints that need the user’s own access token (password change, account deletion, OAuth identities, push device registration) refuse service keys, so the SDK has no functions for them. The SDK’s types send it under the right name and in the right place (the query on a GET or DELETE, the body on a POST, PATCH or PUT; see Where each input goes); a raw userId in its place is refused by most endpoints with 400 <resource>/unsupported-param. See Authentication → Acting as a user.
oauth is intentionally not exposed by this SDK (it’s a browser redirect flow).Auth
Sign up, sign in, token management, password reset
Users
Fetch, update and delete profiles, follow and connection actions
Entities
Create and manage content, reactions, drafts
Comments
Create and manage comments, reactions
Collections
Organize a user’s saved entities into collections
Follows
Read a user’s follow graph and counts
Connections
Mutual connections, pending requests, accept/decline
Spaces
Space CRUD, navigation, slug management
Space Members
Membership, roles, approvals, bans
Space Moderation
Reports, content moderation, rules
Chat
Conversations, messages, members, reactions, read state
Search
Full-text search and AI-powered Q&A
Reports
File content reports and read the moderation queue
App Notifications
Read and mark a user’s in-app notifications
Storage
Upload, fetch, and delete files and images
Return values
Functions resolve to the server’s response body as-is. Fetch-or-create functions (users.fetchOrCreateUserByForeignId, entities.fetchOrCreateEntityByForeignId, chat.createDirectConversation) resolve to { <record>, created }, where created is true when the call created the record (HTTP 201). Actions that are safe to repeat, such as adding a chat member, blocking a user or joining a space, are not fetch-or-create: they give the same response whether or not this call made the change.
Paginated Responses
Functions that return lists use a sharedPaginatedResponse<T> shape:
page and limit to any list function to control pagination. search.searchContent, searchUsers and searchSpaces are not paginated: they resolve to a plain array of results, most similar first, capped by limit.
