Skip to main content

Create Job

Schedule a background job. Currently only scheduled calls are supported.

Endpoint​

POST /api/jobs/create

Authentication​

Requires a valid Bearer JWT. The job is scoped to the token's project_id.

Request body​

{
"job_type": "scheduled_call",
"scheduled_at": 1717000000,
"payload": {
"lead_id": "lead_123"
}
}
FieldTypeRequiredDescription
job_typestringyesMust be scheduled_call.
scheduled_atnumberyesUnix timestamp in seconds. Must be in the future.
payloadobjectyesJob payload. For scheduled_call, { "lead_id": "..." }.

Behavior​

  • Only the scheduled_call job type is supported.
  • scheduled_at must be a future timestamp.
  • payload.lead_id must exist and belong to the same project as the JWT. If the lead belongs to another project, a 401 Unauthorized is returned.

Success response​

{
"success": true,
"message": "Job created successfully",
"job": {
"id": 1,
"job_type": "scheduled_call",
"payload": { "lead_id": "lead_123" },
"status": "pending",
"started_at": null,
"project_id": "project_abc"
}
}

Error responses​

Missing / invalid token

{ "success": false, "message": "Authorization header missing", "job": null }

Invalid request format

{ "success": false, "message": "Invalid request format: ...", "job": null }

Unsupported job type

{ "success": false, "message": "Only 'scheduled_call' job type is supported", "job": null }

Lead not found

{ "success": false, "message": "Lead not found: ...", "job": null }

Lead does not belong to project

{ "success": false, "message": "Lead does not belong to your project", "job": null }

Invalid timestamp

{ "success": false, "message": "Invalid timestamp format", "job": null }

Scheduled time in the past

{ "success": false, "message": "Scheduled time must be in the future", "job": null }

Database error

{ "success": false, "message": "Failed to create job: ...", "job": null }