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/cronjobsRequest Body Parameters
Parameter | Description | Example |
---|---|---|
payload | Your stringified payload | '{"action":"buyGroceriesReminder","values":["eggs","bacon","pasta","bread"]}' |
destination | The endpoint we should send your payload to | https://your-app.com/webhooks/jiter |
expression | A cron expression | '* * * * *' |
Response
Code | Description |
---|---|
200 | Cron job created |
400 | Invalid request body |
500 | Unable to create the cron job |
Example Usage
- TypeScript
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"
}