Skip to main content
The Admin API provides endpoints for managing users, WhatsApp sessions, groups, and campaigns. All endpoints require admin privileges.

getPendingUsers

Retrieve all users awaiting approval (users with GUEST role).

Response

users
array
Array of pending user objects
id
string
User ID
name
string
User’s name
email
string
User’s email address
role
string
User role (always “GUEST” for pending users)
createdAt
Date
Account creation timestamp

Example

const pendingUsers = await trpc.admin.getPendingUsers.query();

console.log(pendingUsers);
// [
//   {
//     id: "clx1234567890",
//     name: "John Doe",
//     email: "[email protected]",
//     role: "GUEST",
//     createdAt: new Date("2024-01-15")
//   }
// ]

getApprovedUsers

Retrieve all approved users (users with USER or ADMIN role).

Response

users
array
Array of approved user objects
id
string
User ID
name
string
User’s name
email
string
User’s email address
role
string
User role (“USER” or “ADMIN”)
createdAt
Date
Account creation timestamp

Example

const approvedUsers = await trpc.admin.getApprovedUsers.query();

console.log(approvedUsers);
// [
//   {
//     id: "clx9876543210",
//     name: "Jane Smith",
//     email: "[email protected]",
//     role: "USER",
//     createdAt: new Date("2024-01-10")
//   }
// ]

approveUser

Approve a pending user by upgrading their role from GUEST to USER.

Input Parameters

userId
string
required
The ID of the user to approve

Response

user
object
The updated user object with USER role

Example

const updatedUser = await trpc.admin.approveUser.mutate({
  userId: "clx1234567890"
});

console.log(updatedUser);
// {
//   id: "clx1234567890",
//   name: "John Doe",
//   email: "[email protected]",
//   role: "USER",
//   ...
// }

revokeAccess

Revoke a user’s access by downgrading their role to GUEST. Cannot revoke admin access.

Input Parameters

userId
string
required
The ID of the user whose access should be revoked

Response

user
object
The updated user object with GUEST role

Example

const updatedUser = await trpc.admin.revokeAccess.mutate({
  userId: "clx1234567890"
});

console.log(updatedUser);
// {
//   id: "clx1234567890",
//   name: "John Doe",
//   role: "GUEST",
//   ...
// }

Error Cases

  • NOT_FOUND: User not found
  • FORBIDDEN: Cannot revoke admin’s access

deleteUser

Permanently delete a user from the system. Cannot delete admin users.

Input Parameters

userId
string
required
The ID of the user to delete

Response

success
boolean
Indicates whether the user was deleted successfully

Example

const result = await trpc.admin.deleteUser.mutate({
  userId: "clx1234567890"
});

console.log(result);
// { success: true }

Error Cases

  • NOT_FOUND: User not found
  • FORBIDDEN: Cannot delete an admin user

addNewUser

Create a new user with USER role and email authentication.

Input Parameters

name
string
required
User’s full name (minimum 1 character)
email
string
required
Valid email address
password
string
required
Password (8-100 characters)

Response

user
object
The newly created user object

Example

const newUser = await trpc.admin.addNewUser.mutate({
  name: "Sarah Johnson",
  email: "[email protected]",
  password: "securePassword123"
});

console.log(newUser);
// {
//   user: {
//     id: "clx5555555555",
//     name: "Sarah Johnson",
//     email: "[email protected]",
//     role: "USER"
//   }
// }

Error Cases

  • BAD_REQUEST: User with this email already exists
  • INTERNAL_SERVER_ERROR: Failed to create user

makeAdmin

Promote a user to admin role.

Input Parameters

userId
string
required
The ID of the user to promote to admin

Response

user
object
The updated user object with ADMIN role

Example

const updatedUser = await trpc.admin.makeAdmin.mutate({
  userId: "clx1234567890"
});

console.log(updatedUser);
// {
//   id: "clx1234567890",
//   name: "John Doe",
//   role: "ADMIN",
//   ...
// }

getWhatsAppSessions

Retrieve all connected WhatsApp sessions across all users.

Response

sessions
array
Array of WhatsApp session objects
id
string
Session ID
sessionName
string
Unique session name
phoneNumber
string
Associated phone number
userId
string
Owner user ID
status
string
Session status (“CONNECTED”)
createdAt
Date
Session creation timestamp
WhatsAppGroups
array
Array of associated WhatsApp groups

Example

const sessions = await trpc.admin.getWhatsAppSessions.query();

console.log(sessions);
// [
//   {
//     id: "cls1234567890",
//     sessionName: "session_1234567890",
//     phoneNumber: "+1234567890",
//     userId: "clx1234567890",
//     status: "CONNECTED",
//     createdAt: new Date("2024-01-01"),
//     WhatsAppGroups: [...]
//   }
// ]

getWhatsAppGroups

Retrieve all WhatsApp groups across all sessions.

Response

groups
array
Array of WhatsApp group objects
id
string
Group database ID
groupName
string
Group name
groupId
string
WhatsApp group ID
sessionId
string
Associated session ID
createdAt
Date
Group creation timestamp
campaigns
array
Array of active campaigns for this group

Example

const groups = await trpc.admin.getWhatsAppGroups.query();

console.log(groups);
// [
//   {
//     id: "clg1234567890",
//     groupName: "Community Group",
//     groupId: "[email protected]",
//     sessionId: "cls1234567890",
//     createdAt: new Date("2024-01-01"),
//     campaigns: [...]
//   }
// ]

getActiveCampaigns

Retrieve all active campaigns across all users (SCHEDULED or IN_PROGRESS status).

Response

campaigns
array
Array of active campaign objects
id
string
Campaign ID
sessionId
string
Associated session ID
groupId
string
Associated group ID
title
string
Campaign title
status
string
Campaign status (“SCHEDULED” or “IN_PROGRESS”)
startDate
Date
Campaign start date
endDate
Date
Campaign end date
group
object
Associated group object

Example

const activeCampaigns = await trpc.admin.getActiveCampaigns.query();

console.log(activeCampaigns);
// [
//   {
//     id: "clc1234567890",
//     sessionId: "cls1234567890",
//     groupId: "clg1234567890",
//     title: "Fundraising Campaign",
//     status: "SCHEDULED",
//     startDate: new Date("2024-02-01"),
//     endDate: new Date("2024-02-28"),
//     group: {...}
//   }
// ]

Type Definitions

type UserRole = 'ADMIN' | 'USER' | 'GUEST';

type WhatsAppSessionStatus = 'DISCONNECTED' | 'CONNECTED';

type CampaignStatus = 
  | 'DRAFT'
  | 'SCHEDULED'
  | 'IN_PROGRESS'
  | 'COMPLETED'
  | 'CANCELLED'
  | 'FAILED';

Build docs developers (and LLMs) love