Documentation

Create a task

Create tasks with the InfluxDB user interface (UI), influx command line interface (CLI), or /api/v2 API.

Before creating a task, review the basics for writing a task.

Create a task in the InfluxDB UI

The InfluxDB UI provides multiple ways to create a task:

Create a task from the Data Explorer

  1. In the navigation menu on the left, select Data Explorer.

  2. Build a query and click Save As in the upper right.

  3. Select the Task heading.

  4. Specify the task options. See Task options for detailed information about each option.

  5. Click Save as Task.

Create a task in the Task UI

  1. In the navigation menu on the left, select Tasks.

  2. Click Create Task in the upper right.

  3. In the left panel, specify the task options. See Task options for detailed information about each option.

  4. In the right panel, enter your task script.

    Leave out the option tasks assignment

    When creating a new task in the InfluxDB Task UI, leave the code editor empty. When you save the task, the Task UI uses the task options you specify in the Task options form to populate option task = {task_options} for you.

    When you edit the saved task, you’ll see the injected option task = {task_options}.

  5. Click Save in the upper right.

Import a task

  1. In the navigation menu on the left, select Tasks.

  2. Click Create Task in the upper right.

  3. In the left panel, specify the task options. See Task options for detailed information about each option.

  4. Paste a raw Flux task in the code editor to the right of the task options fields.

  5. Click Save in the upper right.

Create a task from a template

  1. In the navigation menu on the left, select Settings > Templates.

  2. Find the template you want to use and click its Resources list to expand the list of resources.

  3. In the Resources list, click the task you want to use.

Clone a task

  1. In the navigation menu on the left, select Tasks.

  2. Find the task you would like to clone and click the icon located far right of the task name.

  3. Click Clone.

Create a task using the influx CLI

Use the influx task create command to create a new task. It accepts either a file path or raw Flux.

Create a task using a file

# Syntax
influx task create --org <org-name>  -f </path/to/task-script>

# Example
influx task create --org my-org -f /tasks/cq-mean-1h.flux

Create a task using raw Flux

influx task create --org my-org - # <return> to open stdin pipe

option task = {
  name: "task-name",
  every: 6h
}

# ... Task script ...

# Linux & macOS: <ctrl-d> to close the pipe and submit the command
# Windows: <enter>, then <ctrl-d>, then <enter> to close the pipe and submit the command

Create a task using the InfluxDB API

Use the /api/v2/tasks InfluxDB API endpoint to create a task.

POST https://127.0.0.1:8086/api/v2/tasks/

Provide the following in your API request:

Request headers
  • Content-Type: application/json
  • Authorization: Token INFLUX_API_TOKEN
Request body

JSON object with the following fields:

  • flux: raw Flux task string that contains a task option and a query.
  • orgID: your InfluxDB organization ID
  • status: task status (“active” or “inactive”)
  • description: task description
curl --request POST 'https://127.0.0.1:8086/api/v2/tasks' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Token INFLUX_API_TOKEN' \
  --data-raw '{
    "flux": "option task = {name: \"CPU Total 1 Hour New\", every: 1h}\n\nfrom(bucket: \"telegraf\")\n\t|> range(start: -1h)\n\t|> filter(fn: (r) =>\n\t\t(r._measurement == \"cpu\"))\n\t|> filter(fn: (r) =>\n\t\t(r._field == \"usage_system\"))\n\t|> filter(fn: (r) =>\n\t\t(r.cpu == \"cpu-total\"))\n\t|> aggregateWindow(every: 1h, fn: max)\n\t|> to(bucket: \"cpu_usage_user_total_1h\", org: \"INFLUX_ORG\")",
    "orgID": "INFLUX_ORG_ID",
    "status": "active",
    "description": "This task downsamples CPU data every hour"
}'

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered