Skip to main content

Create a Cron Job

caution

Cron jobs are currently in ALPHA and are not considered stable. This feature may change at any time, please use with caution.

Creates a Cron job to trigger on a set schedule

POST https://app.jiter.dev/api/cronjobs

Request Body Parameters

ParameterDescriptionExample
payloadYour stringified payload'{"action":"buyGroceriesReminder","values":["eggs","bacon","pasta","bread"]}'
destinationThe endpoint we should send your payload tohttps://your-app.com/webhooks/jiter
expressionA cron expression'* * * * *'

Response

CodeDescription
200Cron job created
400Invalid request body
500Unable to create the cron job

Example Usage

index.ts
import axios from "axios";

const apiBaseUrl = "https://app.jiter.dev/api";

const createCronJob = async () => {
try {
const { data } = await axios.post(
`${apiBaseUrl}/cronjobs`,
{
destination: "https://your-app.com/webhooks/jiter",
expression: "* * * * *",
payload: JSON.stringify({
action: "buyGroceriesReminder",
values: ["eggs", "bacon", "pasta", "bread"],
}),
},
{ headers: { "x-api-key": "YOUR_API_KEY" } }
);

console.log("Cron Job created 🎉", data);
} catch (error) {
console.log("Unable to create Cron Job", error);
}
};

createCronJob();

Example Success Response

{
"id": "9",
"history": [],
"status": "Active",
"destination": "https://your-app.com/webhooks/jiter",
"org": "3",
"payload": "{'action':'buyGroceriesReminder','values':['eggs','bacon','pasta','bread']}",
"expression": "* * * * *",
"nextExecutionStatus": "Pending",
"nextExecutionDate": "2022-10-25T18:27:00.000Z",
"createdAt": "2022-10-25T18:26:04.000Z",
"updatedAt": "2022-10-25T18:26:04.000Z"
}

Example Error Response

{
"message": "Please enter a valid cron expression"
}