Skip to content

Add a Cron Job

Add a cron job.

Method

POST

Endpoint

https://api.easycron.com/v1/cron-jobs

Example API call

Terminal window
curl \
--include \
--request POST \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <API_KEY>' \
--data '{"url": "https://www.example.com", "cron_expression": "* * * * * *"}' \
"https://api.easycron.com/v1/cron-jobs"

Example Success Response

Together with the HTTP code 201, the following content will be responded:

{"cron_job_id":CRON_JOB_ID}

Example Failure Response

Together with the HTTP code of the error, the following error message will be responded:

{"message":"ERROR_MESSAGE"}

JSON Parameters in Request Body

nametyperequireddefaultdescriptionlimits
urlstringrequiredURL to call.Maximum 1024 chars
cron_expressionstringrequiredCron expression following these syntax.Maximum 1000 chars
http_auth_userstringoptionalHTTP basic authentication user.Maximum 100 chars
http_auth_pwstringoptionalHTTP basic authentication password.Maximum 100 chars
timezone_fromintoptional1Specify the source of timezone used to calculate the executing times of the cron job.
Allowed values:
  • 1: use the timezone in your EasyCron account.
  • 2: use the timezone in the cron job.
timezoneintoptionalUTCTimezone used to calculate executing times when timezone_from = 2.
Allowed values: TZ Timezones.
http_methodstringoptionalGETHTTP method used in the HTTP requests to your cron job script.
Allowed values: GET, POST, HEAD, PUT, PATCH, DELETE, CONNECT, OPTIONS and TRACE.
http_headersstringoptionalHTTP headers sent with the HTTP requests to your cron job script.Maximum 10240 chars
http_message_bodystringoptionalHTTP message body sent with the HTTP requests to your cron job script if the HTTP method is POST, PUT or PATCH. It contains variable-value pairs or JSON payload. E.g. param1=val1&param2=val2 or {"name":"John","age":30}.Maximum 10240 chars
timeoutintoptional0The max allowed execution time (in seconds) of your cron job. Execeeding this time, your cron job will time out and be marked as “failed”.
Allowed values:
  • 0: use your plan’s default timeout.
  • Any value up to your plan’s default timeout.
success_criterionintoptional1Rules for considering if the execution of a cron job succeeded or failed.
Allowed values:
  • 1: consider execution succeeded when the HTTP code is 2xx.
  • 2: consider execution succeeded when the HTTP code is 2xx and the HTTP body messge matches success_regexp.
  • 3: consider execution failed when the HTTP code is 2xx and the HTTP body messge matches failure_regexp.
success_regexpstringoptionalThe regular expression to match when success_criterion is set to 2.Maximum 255 chars
failure_regexpstringoptionalThe regular expression to match when success_criterion is set to 3.Maximum 255 chars
send_emailintoptional0Email notification setting of the cron job.
Allowed values:
  • 0: never send email notification.
  • 1: send email if execution fails.
email_thresholdintoptional1Only after encountering this amount of failures, the failure notification email will get sent.
Allowed values: 1 to 5.
send_slackintoptional0Slack notification setting of the cron job.
Allowed values:
  • 0: never send Slack notification.
  • 1: send Slack notification if execution fails.
  • 2: send Slack notification after each execution.
slack_sensitivityintoptional1Only after encountering this amount of failures, the failure Slack notification will get sent.
Allowed values: 1 to 5.
slack_urlstringoptional, required if send_slack is 1 or 2URL that the Slack notification is sent to.Maximum 1024 chars
send_webhookintoptional0Webhook notification setting of the cron job.
Allowed values:
  • 0: never send webhook notification.
  • 1: send webhook if execution fails.
  • 2: send webhook after each execution.
webhook_urlstringoptional, required if send_webhook is 1 or 2URL that the webhook request is sent to.Maximum 1024 chars
webhook_http_methodstringoptionalGETHTTP method that your cron job webhook requests will use.
Allowed values: GET, POST, HEAD, PUT, PATCH, DELETE, CONNECT, OPTIONS and TRACE.
webhook_datastring arrayoptionalInformation that your cron job webhook requests will send. Valid values include CRON_JOB_ID, CRON_JOB_NAME, CRON_JOB_URL, CRON_JOB_HTTP_STATUS_CODE, CRON_JOB_EXECUTION_STATUS and CRON_JOB_EXECUTION_ERROR. E.g. ["CRON_JOB_ID","CRON_JOB_NAME"]
statusintoptional1Status of the cron job.
Allowed values:
  • 0: create a disabled cron job.
  • 1: create an enabled cron job.
cron_job_namestringoptionalName of the cron job.Maximum 100 chars
descriptionstringoptionalDescription of the cron job.Maximum 1024 chars
cron_job_group_idintoptional0Group ID of the cron job. You could find the group ID in the group pages. If this parameter is set to 0, the cron job doesn’t belong to any group.