Quickstart: create and run a job

Create a job that calls your app every day, run it straight away, and read what happened.

This quickstart creates a job that calls your app every day at 2:00 in Dar es Salaam, runs it once straight away, and reads the result.

Before you begin

  • Set up your environment, so SCHEDULER_TOKEN and PROJECT_ID are set.
  • Have an HTTPS address in your app that answers POST requests with a 2xx status. This quickstart uses https://mail.example.com/tasks/report.

Create and run a job

  1. Create the job

    curl -X POST "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs" \
      -H "Authorization: Bearer $SCHEDULER_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "Nightly report",
        "schedule": "0 2 * * *",
        "timeZone": "Africa/Dar_es_Salaam",
        "target": {
          "url": "https://mail.example.com/tasks/report",
          "method": "POST"
        }
      }'

    The answer holds the new job. Copy its id into a variable:

    export JOB_ID="the-job-id"

    Its nextRunAt says when it runs next.

  2. Run it now

    You do not have to wait for the schedule:

    curl -X POST "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID/run" \
      -H "Authorization: Bearer $SCHEDULER_TOKEN"

    The answer is the new run, with trigger set to manual. In the console, you can do the same with Run now on the job’s page.

  3. Read the result

    List the job’s runs. The newest is first:

    curl "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID/runs" \
      -H "Authorization: Bearer $SCHEDULER_TOKEN"

    When your app answered with a 2xx status, the run’s status is succeeded. If it is failed, lastErrorClass and lastError say why. See View runs.

Clean up

Delete the job if you do not want it to keep running. This deletes its runs too, and cannot be undone:

curl -X DELETE "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID" \
  -H "Authorization: Bearer $SCHEDULER_TOKEN"

What’s next

Last updated