Create a task
This page documents an earlier version of InfluxDB. InfluxDB v2.6 is the latest stable version. View this page in the v2.6 documentation.
InfluxDB provides multiple ways to create tasks both in the InfluxDB user interface (UI)
and the influx
command line interface (CLI).
Before creating a task, review the basics criteria 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
- Create a task in the Task UI
- Import a task
- Create a task from a template
- Clone a task
Create a task from the Data Explorer
In the navigation menu on the left, select Explore (Data Explorer).
Build a query and click Save As in the upper right.
Select the Task option.
Specify the task options. See Task options for detailed information about each option.
Select a token to use from the Token dropdown.
Click Save as Task.
Create a task in the Task UI
In the navigation menu on the left, select Tasks.
Click Create Task in the upper right.
Select New Task.
In the left panel, specify the task options. See Task options for detailed information about each option.
Select a token to use from the Token dropdown.
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 out the
option task
assignment that defines task options. The InfluxDB UI injects this code using settings specified in the Task options fields in the left panel when you save the task.Click Save in the upper right.
Import a task
In the navigation menu on the left, select Tasks.
Click + Create Task in the upper right.
Select Import Task.
Upload a JSON task file using one of the following options:
- Drag and drop a JSON task file in the specified area.
- Click to upload and the area to select the JSON task from from your file manager.
- Select the JSON option and paste in raw task JSON.
Click Import JSON as Task.
Create a task from a template
In the navigation menu on the left, select Settings > Templates.
Select Templates.
Hover over the template to use to create the task and click Create.
Clone a task
In the navigation menu on the left, select Tasks.
Hover over the task you would like to clone and click the icon that appears.
Click Clone.
Create a task using the influx CLI
Use 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 ...
# <ctrl-d> to close the pipe and submit the command
Create a task using the InfluxDB API
Send a request using the POST method to the /api/v2/tasks
InfluxDB API endpoint.
Provide the following in your API request:
Request headers
- Content-Type: application/json
- Authorization: Token
YOUR_INFLUXDB_TOKEN
Request body
JSON object with the following fields:
- flux : raw Flux task string
- orgID: your InfluxDB organization ID
- status: task status (“active” or “inactive”)
- description: task description
curl --request POST 'https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/tasks' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token INFLUX_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"
}'
Replace the following:
INFLUX_TOKEN
: your InfluxDB API tokenINFLUX_ORG
: your InfluxDB organization nameINFLUX_ORG_ID
: your InfluxDB organization ID
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.