HTTP interface for tasks

The HTTP API for tasks lets you can manage the periodic or timed execution of server-side JavaScript code

List all tasks

get /_db/{database-name}/_api/tasks/
fetches all existing tasks on the server
Path Parameters
  • The name of a database. Which database you use doesn’t matter as long as the user account you authenticate with has at least read access to this database.

Query Parameters
    HTTP Headers
      Responses
      • The list of tasks

          Response Body application/json
        • a list of all tasks

          • The JavaScript function for this task.

          • The timestamp when this task was created.

          • The database this task belongs to.

          • A string identifying the task.

          • A user-friendly name for the task.

          • Time offset in seconds from the created timestamp.

          • This task should run each period seconds.

          • What type of task is this [ periodic, timed]

            • periodic are tasks that repeat periodically
            • timed are tasks that execute once at a specific time

      Examples

      Fetching all tasks

      curl --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks'
      Show output

      Get a task

      get /_db/{database-name}/_api/tasks/{id}
      fetches one existing task on the server specified by id
      Path Parameters
      • The name of a database. Which database you use doesn’t matter as long as the user account you authenticate with has at least read access to this database.

      • The id of the task to fetch.

      Query Parameters
        HTTP Headers
          Responses
          • The requested task

              Response Body application/json
            • The JavaScript function for this task.

            • The timestamp when this task was created.

            • The database this task belongs to.

            • A string identifying the task.

            • A user-friendly name for the task.

            • Time offset in seconds from the created timestamp.

            • This task should run each period seconds.

            • What type of task is this [ periodic, timed]

              • periodic are tasks that repeat periodically
              • timed are tasks that execute once at a specific time

          Examples

          Fetching a single task by its id

          curl -X POST --header 'accept: application/json' --data-binary @- --dump - 'http://localhost:8529/_api/tasks' <<'EOF'
          {"id":"testTask","command":"console.log('Hello from task!');","offset":10000}
          EOF
          
          curl --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks/testTask'
          Show output

          Trying to fetch a non-existing task

          curl --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks/non-existing-task'
          Show output

          Create a task

          post /_db/{database-name}/_api/tasks
          creates a new task with a generated id
          Path Parameters
          • The name of the database.

          Query Parameters
            HTTP Headers
              Request Body application/json
              • The JavaScript code to be executed

              • The name of the task

              • Number of seconds initial delay

              • The parameters to be passed into command

              • number of seconds between the executions

              Responses
              • The task was registered

                  Response Body application/json
                • The status code, 200 in this case.

                • the javascript function for this task

                • The timestamp when this task was created

                • the database this task belongs to

                • false in this case

                • A string identifying the task

                • time offset in seconds from the created timestamp

                • this task should run each period seconds

                • What type of task is this [ periodic, timed]

                  • periodic are tasks that repeat periodically
                  • timed are tasks that execute once at a specific time

              • If the post body is not accurate, a HTTP 400 is returned.

              Examples

              curl -X POST --header 'accept: application/json' --data-binary @- --dump - 'http://localhost:8529/_api/tasks/' <<'EOF'
              {
                "name": "SampleTask",
                "command": "(function(params) { require('@arangodb').print(params); })(params)",
                "params": {
                  "foo": "bar",
                  "bar": "foo"
                },
                "period": 2
              }
              EOF
              
              curl -X DELETE --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks/69833'
              Show output

              Create a task with ID

              put /_db/{database-name}/_api/tasks/{id}

              Registers a new task with the specified ID.

              Not compatible with load balancers.

              Path Parameters
              • The name of the database.

              • The id of the task to create

              Query Parameters
                HTTP Headers
                  Request Body application/json
                  • The JavaScript code to be executed

                  • The name of the task

                  • Number of seconds initial delay

                  • The parameters to be passed into command

                  • number of seconds between the executions

                  Responses
                  • If the task id already exists or the rest body is not accurate, HTTP 400 is returned.

                  Examples

                  curl -X PUT --header 'accept: application/json' --data-binary @- --dump - 'http://localhost:8529/_api/tasks/sampleTask' <<'EOF'
                  {
                    "id": "SampleTask",
                    "name": "SampleTask",
                    "command": "(function(params) { require('@arangodb').print(params); })(params)",
                    "params": {
                      "foo": "bar",
                      "bar": "foo"
                    },
                    "period": 2
                  }
                  EOF
                  Show output

                  Delete a task

                  delete /_db/{database-name}/_api/tasks/{id}
                  Deletes the task identified by id on the server.
                  Path Parameters
                  • The name of a database. Which database you use doesn’t matter as long as the user account you authenticate with has administrate access to this database.

                  • The id of the task to delete.

                  Query Parameters
                    HTTP Headers
                      Responses
                      • If the task was deleted, HTTP 200 is returned.

                          Response Body application/json
                        • The status code, 200 in this case.

                        • false in this case

                      • If the task id is unknown, then an HTTP 404 is returned.

                          Response Body application/json
                        • The status code, 404 in this case.

                        • true in this case

                        • A plain text message stating what went wrong.

                      Examples

                      Try to delete a non-existent task:

                      curl -X DELETE --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks/NoTaskWithThatName'
                      Show output

                      Remove existing task:

                      curl -X DELETE --header 'accept: application/json' --dump - 'http://localhost:8529/_api/tasks/SampleTask'
                      Show output