Teams in Inbox organize your account links, prospects, and conversations. This guide covers retrieving team information and managing team members via the API.
Assign threads to team members for workload distribution:
Copy
// Assign a thread to a memberawait client.patch(`/threads/${threadId}`, { assigneeId: "r3km7xj9wq5p2bvnhfdteoly",});// Unassign a threadawait client.patch(`/threads/${threadId}`, { assigneeId: null,});
Assign to the team member with the fewest open threads. Since the API doesn’t return a total count, you need to paginate to get real numbers:
Copy
async function countThreadsForMember(memberId: string): Promise<number> { let count = 0; let cursorId: string | undefined; let cursorTimestamp: string | undefined; do { const { data } = await client.get("/threads", { params: { "filters[assignees][selectedIds][0]": memberId, inbox: "default", limit: 100, ...(cursorId && { cursorId, cursorTimestamp }), }, }); count += data.threads.length; cursorId = data.nextCursor?.id; cursorTimestamp = data.nextCursor?.timestamp; } while (cursorId); return count;}async function assignToLeastBusy(threadId: string) { const { data: members } = await client.get("/members"); let minMember = ""; let minCount = Infinity; for (const member of members) { if (member.role === "owner") continue; const count = await countThreadsForMember(member.id); if (count < minCount) { minCount = count; minMember = member.id; } } if (minMember) { await client.patch(`/threads/${threadId}`, { assigneeId: minMember, }); console.log(`Assigned to ${minMember} (${minCount} open threads)`); }}
This makes multiple API calls per member. For teams with many members or
threads, consider caching workload counts and refreshing periodically rather
than computing on every assignment.