Skip to content

Agent Schedule API

The Agent Schedule API lets agent services read user schedules, create scheduled tasks, and run scheduling calculations such as business-day counts and task end times.

Every request requires both an organizationId and an organizationApiKey. Send them as headers:

X-Organization-Id: <your-organization-id>
X-Organization-Api-Key: <your-agent-api-key>

or as explicit query parameters (GET) or body fields (POST).

  • Users must belong to the organisation to be included in queries or task assignments.
  • 403 Forbidden is returned if users don’t belong to the organisation.
  • 404 Not Found is returned if users don’t exist.

Retrieve tasks and schedules for specified users within a date range.

GET /api/agents/schedules
ParameterTypeRequiredDescription
organizationIdstringYesOrganisation to filter tasks by.
organizationApiKeystringYesSigned API key from the agent payload.
userIdsstringYesComma-separated list of user IDs.
startDatestringYesStart date in ISO 8601 format (e.g. 2025-10-01).
endDatestringYesEnd date in ISO 8601 format (e.g. 2025-10-31).
Terminal window
curl -X GET "https://api.runnit.io/api/agents/schedules?organizationId=<your-organization-id>&userIds=user-uuid-1,user-uuid-2&startDate=2025-10-01&endDate=2025-10-31" \
-H "X-Organization-Id: <your-organization-id>" \
-H "X-Organization-Api-Key: <your-agent-api-key>"
{
"organizationId": "org-uuid",
"startDate": "2025-10-01T00:00:00.000Z",
"endDate": "2025-10-31T23:59:59.999Z",
"userSchedules": [
{
"userId": "user-uuid-1",
"userDisplayName": "John Doe",
"userEmail": "john@example.com",
"calendarEntries": [
{
"id": "schedule-entry-uuid-1",
"taskId": "task-uuid-1",
"taskName": "Design Homepage Mockup",
"taskDescription": "Create high-fidelity mockups for the homepage",
"taskNumber": "TASK-001",
"status": "in_progress",
"priority": "high",
"segmentIndex": 0,
"totalSegments": 3,
"isOverdue": false,
"daysOverdue": 0,
"startTime": "2025-10-01T09:00:00.000Z",
"endTime": "2025-10-01T17:30:00.000Z",
"durationMinutes": 450,
"estimatedHours": 7.5,
"projectId": "project-uuid-1",
"projectName": "Website Redesign",
"projectJobNumber": "JOB-2025-001",
"clientName": "Acme Corp",
"assignedToId": "user-uuid-1",
"tags": ["design", "ui/ux"]
}
]
}
]
}
FieldTypeDescription
idstringUnique schedule entry identifier.
taskIdstringParent task identifier.
taskNamestringName of the task.
taskDescriptionstringDetailed description (optional).
taskNumberstringTask number (e.g. TASK-001).
statusstringpending, scheduled, in_progress, completed, or cancelled.
prioritystringlow, medium, high, or critical.
segmentIndexnumberZero-based index of this segment for the task.
totalSegmentsnumberTotal segments scheduled for the task.
isOverduebooleanWhether this segment starts after the brief due date.
daysOverduenumberDays past due (0 if on time).
startTimestringSegment start time (ISO 8601).
endTimestringSegment end time (ISO 8601).
durationMinutesnumberDuration between start and end time, in minutes.
estimatedHoursnumberEstimated hours for the task (optional).
projectIdstringAssociated project ID.
projectNamestringName of the project.
projectJobNumberstringProject job number.
clientNamestringClient name, if available.
assignedToIdstringUser this task is assigned to.
tagsstring[]Tags (optional).

The endpoint returns tasks that have both a planned start and end date, are not cancelled, overlap the requested date range, belong to the organisation, and are assigned to one of the requested users. Entries are grouped by user and sorted chronologically.

Create a new scheduled task for a user.

POST /api/agents/tasks
FieldTypeRequiredDescription
organizationIdstringYesOrganisation for security validation.
organizationApiKeystringYesSigned API key from the agent payload.
projectIdstringYesThe project UUID (an existing project, not a brief job UUID).
namestringYesTask name.
statusstringYespending, scheduled, in_progress, completed, or cancelled.
prioritystringYeslow, medium, high, or critical.
assignedToIdstringYesUser this task is assigned to.
plannedStartDatestringYesISO 8601 datetime when the task should start.
plannedEndDatestringYesISO 8601 datetime when the task should end.
descriptionstringNoTask description.
estimatedHoursnumberNoEstimated hours to complete the task.
tagsstring[]NoTags.
metadataobjectNoAdditional metadata (see below).

Tasks cannot be scheduled in the past: plannedStartDate must be at or after the current time.

When a task is scheduled past the project deadline, include these metadata fields:

{
"briefJobId": "job-uuid-from-brief",
"scheduledPastDueDate": true,
"daysOverdue": 3,
"originalTaskId": "temp-task-2",
"schedulingNotes": "User's calendar was fully booked through the deadline"
}
Terminal window
curl -X POST https://api.runnit.io/api/agents/tasks \
-H "Content-Type: application/json" \
-d '{
"organizationId": "<your-organization-id>",
"organizationApiKey": "<your-agent-api-key>",
"projectId": "project-uuid",
"name": "Design homepage mockups",
"description": "Create high-fidelity mockups for the homepage",
"status": "scheduled",
"priority": "high",
"assignedToId": "user-uuid-1",
"estimatedHours": 16,
"plannedStartDate": "2025-10-15T09:00:00.000Z",
"plannedEndDate": "2025-10-17T16:30:00.000Z",
"tags": ["design", "mockups"]
}'
{
"success": true,
"task": {
"id": "created-task-uuid",
"projectId": "project-uuid",
"taskNumber": "TASK-123",
"name": "Design homepage mockups",
"status": "scheduled",
"priority": "high",
"assignedToId": "user-uuid-1",
"estimatedHours": 16,
"plannedStartDate": "2025-10-15T09:00:00.000Z",
"plannedEndDate": "2025-10-17T16:30:00.000Z",
"tags": ["design", "mockups"],
"createdAt": "2025-10-12T10:30:00.000Z",
"updatedAt": "2025-10-12T10:30:00.000Z"
}
}
// 400 Bad Request: missing field
{ "success": false, "error": "assignedToId is required", "statusCode": 400 }
// 400 Bad Request: scheduled in the past
{ "error": "Cannot schedule tasks in the past." }
// 403 Forbidden: user not in organisation
{ "error": "User user-uuid-1 does not belong to organization org-uuid" }
// 404 Not Found
{ "success": false, "error": "User not found: user-uuid-1", "statusCode": 404 }

Calculate the number of business days (excluding weekends) between two dates.

GET /api/agents/calculate-business-days
ParameterTypeRequiredDescription
organizationIdstringYesOrganisation for security validation.
organizationApiKeystringYesSigned API key from the agent payload.
startDatestringYesStart date (ISO 8601).
endDatestringYesEnd date (ISO 8601).
{
"success": true,
"startDate": "2025-11-15T00:00:00.000Z",
"endDate": "2025-11-18T00:00:00.000Z",
"businessDays": 2,
"calendarDays": 3
}

Calculate when a task should end based on estimated hours, accounting for weekends and working hours per day.

POST /api/agents/calculate-task-schedule
FieldTypeRequiredDescription
organizationIdstringYesOrganisation for security validation.
organizationApiKeystringYesSigned API key from the agent payload.
estimatedHoursnumberYesEstimated hours for the task.
startDateTimestringYesStart date/time (ISO 8601).
hoursPerDaynumberNoWorking hours per day. Defaults to 7.5.
{
"success": true,
"startTime": "2025-10-15T09:00:00.000Z",
"endTime": "2025-10-17T16:30:00.000Z",
"durationMinutes": 960,
"businessDays": 3,
"input": {
"estimatedHours": 16,
"startDateTime": "2025-10-15T09:00:00.000Z",
"hoursPerDay": 7.5
}
}

Use the returned startTime and endTime as plannedStartDate and plannedEndDate when creating a task.