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
Array of pending user objectsUser role (always “GUEST” for pending users)
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
Array of approved user objectsUser role (“USER” or “ADMIN”)
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.
The ID of the user to approve
Response
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.
The ID of the user whose access should be revoked
Response
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.
The ID of the user to delete
Response
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.
User’s full name (minimum 1 character)
Password (8-100 characters)
Response
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.
The ID of the user to promote to admin
Response
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
Array of WhatsApp session objectsSession status (“CONNECTED”)
Session creation timestamp
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
Array of WhatsApp group objectsArray 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
Array of active campaign objectsCampaign status (“SCHEDULED” or “IN_PROGRESS”)
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';