Sales rep and task endpoints

See Sales reps and follow-up tasks for the rules.

Sales reps

GET /api/sales-reps

page, pageSize.

Filters

search, status

POST /api/sales-reps

Creates a rep: name, email, and optionally profileId, hubspotOwnerId, nooksUserId, activeListId, hubspotCallSegmentId.

Unique on (subscriptionId, email). A rep can exist before having a Supabase account — profileId is optional.

GET|PATCH|DELETE /api/sales-reps/{id}

Populate nooksUserId for Nooks call attribution to work by its primary path; email matching is only a fallback.

GET /api/sales-reps/{id}/calls

Calls attributed to the rep (page, pageSize) — Call.salesRepId, populated by the Nooks handler.

GET /api/sales-reps/{id}/tasks

The rep’s follow-up tasks (page, pageSize).

GET /api/sales-reps/profile-match?email=<email>

Resolves a signed-in user to their SalesRep record, so the dashboard can show "my tasks" without the user knowing their rep id.

Follow-up tasks

GET /api/follow-up-tasks

Validated by FollowUpTasksListQuerySchema. page, pageSize.

Parameter Filter

search

Contact or note text

status

pending, in_progress, completed, skipped, failed

type

call, email, sequence_enrollment

sales_rep_id

Assignee

due_filter

Relative due-date bucket (overdue, today, upcoming)

sort

Sort order

created_from, created_to

Creation date range

Response

{ data, total, page, pageSize, stats }

The stats block is computed in the same request as the page (getStats(subscriptionId)), so the task board renders its counters without a second round trip.

POST /api/follow-up-tasks

Validated by CreateFollowUpTaskSchema: salesRepId, contactId, type, dueAt, notes, and optionally campaignTargetId or contactSequenceId.

GET /api/follow-up-tasks/{id}

PATCH /api/follow-up-tasks/{id}

Updates status, dueAt, notes, escalationStage and the per-platform sync fields. Completing a task should also cancel its pending escalation run using the stored inngestRunId.

Repository and API mapping: lib/repositories/follow-up-task-repository.ts (mapFollowUpTaskToApi).