Queries
SDK query methods for reading start.chat data
All queries are one-shot REST calls. Call setup() first.
import { setup, query } from '@start-chat/sdk'
await setup({ apiKey: 'sk_live_your_api_key' })
const channels = await query.channelsByServer({ serverId: 'srv_...' })
serverById
Get server details by ID.
const result = await query.serverById({ serverId: 'srv_...' })
Response:
{
"id": "srv_acme",
"name": "Acme Corp",
"description": "Our team workspace",
"icon": "https://...",
"creatorId": "usr_alice",
"createdAt": 1709251200000,
"memberCount": 42,
"roles": [
{ "id": "role_admin", "name": "Admin", "color": "#EF4444", "canAdmin": true },
{ "id": "role_team", "name": "Team", "color": "#3B82F6", "canEditData": true }
]
}
serverMembers
List members of a server.
const result = await query.serverMembers({ serverId: 'srv_...' })
Response:
[
{
"serverId": "srv_acme",
"userId": "usr_alice",
"joinedAt": 1709251200000,
"user": {
"id": "usr_alice",
"name": "Alice",
"username": "alice",
"image": "https://..."
}
},
{
"serverId": "srv_acme",
"userId": "usr_bob",
"joinedAt": 1709337600000,
"user": { "id": "usr_bob", "name": "Bob", "username": "bob", "image": "https://..." }
}
]
userServers
List servers the authenticated user belongs to.
const result = await query.userServers({})
Response:
[
{
"id": "srv_acme",
"name": "Acme Corp",
"icon": "https://...",
"member": { "joinedAt": 1709251200000 }
},
{
"id": "srv_oss",
"name": "Open Source",
"icon": "https://...",
"member": { "joinedAt": 1709337600000 }
}
]
searchJoinableServers
Search for public servers the user can join.
const result = await query.searchJoinableServers({})
channelsByServer
List all channels in a server.
const result = await query.channelsByServer({ serverId: 'srv_...' })
Response:
[
{ id: "ch_general", name: "general", private: false, ... },
{ id: "ch_random", name: "random", private: false, ... },
{ id: "ch_eng", name: "engineering", private: true, ... }
]
channelById
Get channel details by ID.
const result = await query.channelById({ channelId: 'ch_...' })
Response:
{
"id": "ch_general",
"serverId": "srv_acme",
"name": "general",
"description": "General discussion",
"private": false,
"readonly": false,
"deleted": false,
"createdAt": 1709251200000
}
channelMessages
Fetch messages in a channel. Supports cursor-based pagination, filtering, and limit control.
const result = await query.channelMessages({ serverId: 'srv_...', channelId: 'ch_...' })
Response:
[
{
"id": "msg_abc123",
"content": "Hello!",
"type": "person",
"createdAt": 1709251200000,
"order": "0000001",
"creator": { "id": "usr_alice", "name": "Alice", "username": "alice" },
"attachments": [],
"reactionStats": []
},
{
"id": "msg_def456",
"content": "Hey there!",
"type": "person",
"createdAt": 1709251260000,
"order": "0000002",
"creator": { "id": "usr_bob", "name": "Bob", "username": "bob" },
"attachments": [],
"reactionStats": []
}
]
messageById
Get a single message by ID.
const result = await query.messageById({ messageId: 'msg_...' })
Response:
{
"id": "msg_abc123",
"channelId": "ch_general",
"content": "Hello everyone!",
"type": "person",
"createdAt": 1709251200000,
"deleted": false,
"creator": {
"id": "usr_alice",
"name": "Alice",
"username": "alice",
"image": "https://..."
},
"attachments": [],
"reactionStats": [{ "content": "thumbsup", "count": 3 }]
}
threadWithMessages
Get a thread and all its messages.
const result = await query.threadWithMessages({
threadId: 'thr_...',
serverId: 'srv_...',
})
Response:
{
id: "thr_xyz789",
channelId: "ch_general",
serverId: "srv_acme",
title: "Feature discussion",
replyCount: 5,
createdAt: 1709251200000,
creator: { id: "usr_alice", name: "Alice" },
messages: [
{ id: "msg_1", content: "What about...", creator: { ... } },
{ id: "msg_2", content: "Good idea!", creator: { ... } }
]
}
threadById
Get thread metadata by ID.
const result = await query.threadById({ threadId: 'thr_...' })
userById
Get user profile by ID.
const result = await query.userById({ userId: 'usr_...' })