content/kapacitor/v1/working/flux/manage/update.md
Use the kapacitor CLI or the Kapacitor HTTP API to update Kapacitor Flux tasks.
{{< tabs-wrapper >}} {{% tabs %}} CLI API {{% /tabs %}}
<!----------------------------- BEGIN CLI content ----------------------------->{{% tab-content %}}
Use the kapacitor flux task update command to update Kapacitor Flux tasks.
Provide the following flags:
{{< req type="key" >}}
-i, --id: Task ID--status: Updated tasks status (active or inactive)-f, --file: Path to updated Flux script filekapacitor flux task update \
--id 000x00xX0xXXx00 \
--file /path/to/updated-task.flux
kapacitor flux task update \
--id 000x00xX0xXXx00 \
--status inactive
{{% /tab-content %}}
<!------------------------------ END CLI content ------------------------------> <!----------------------------- BEGIN API content ----------------------------->{{% tab-content %}}
Use the following request method and endpoint to update a new Kapacitor Flux task.
{{< api-endpoint method="patch" endpoint="/kapacitor/v1/api/v2/tasks/{taskID}" >}}
Provide the following with your request ({{< req type="key" >}}):
JSON object with the following schema:
cron Flux task optionevery Flux task optionname Flux task optionoffset Flux task optionactive or inactive)The following examples use the task ID 000x00xX0xXXx00.
{{< keep-url >}}
curl --request PATCH 'http://localhost:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
--header 'Content-Type: application/json' \
--data-raw '{
"flux": "option task = {name: \"Updated task name\", every: 1h}\n\nhost = \"http://localhost:8086\"\ntoken = \"\"\n\nfrom(bucket: \"db/rp\", host:host, token:token)\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\", host:host, token:token)"
}'
curl --request PATCH 'http://localhost:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
--header 'Content-Type: application/json' \
--data-raw '{"status": "inactive"}'
curl --request PATCH 'http://localhost:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
--header 'Content-Type: application/json' \
--data-raw '{
"every": "1d",
"name": "New task name",
"offset": "15m"
}'
{{% /tab-content %}}
<!------------------------------ END API content ------------------------------>{{< /tabs-wrapper >}}