Delete data with Flux Language

Hi All,

I’m trying to delete some data from a bucket with no results.
I’m trying with Flux Language

import "http"
import "json"

http.post(
  url: "http://10.67.61.169/:8086/api/v2/delete?bucket=MyBucket&org=MyOrg",
  headers: {Accept: "application/json", Authorization: "Token TokenFromAPIWEBaPage", "Content-Type": "application/json"},
  data: json.encode(v: {
  "predicate": "_measurement=\"R12_WD\")",
  "start": "2020-06-30T18:00:00Z",
  "stop": "2020-07-03T00:00:00Z"})
)

This, from the InfluxDB script builder results in

error calling function "post" @4:1-11:2: connectex: The connection could not be established. Persistent rejection of the target computer.

I know there are other methods ( CLI or Curl ) for deleting data but I can’t get them to work.

Any help?

Cheers,

InfluxDB v2.3.0+SNAPSHOT.090f681737

Hello @Cristian_Bertulli,

Are you using an all access token?

I would try the following with the CLI:

influx delete --bucket MyBucket \
  --start '2020-06-30T18:00:00Z' \
  --stop '2020-07-03T00:00:00Z' \
  --predicate '_measurement="R12_WD"'

After setting up your InfluxDB CLI config with

influx config create --config-name <config-name> \
  --host-url https://us-west-2-1.aws.cloud2.influxdata.com \
  --org <your-org> \
  --token <your-auth-token> \
  --active

Make sure you’re using the right config with

influx config ls 

The following worked for me:

import "array"
import "http"
import "json"

http.post(
  url: "https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/delete?bucket=test&org=myorg@influxdata.com",
  headers: {Accept: "application/json", Authorization: "Token myAllAccessToken", "Content-Type": "application/json"},
  data: json.encode(v: {
  "predicate": "_measurement=\"meas\")",
  "start": "2021-07-05T00:00:00Z",
  "stop": "2021-07-06T00:00:00Z"})
)

array.from(rows: [{foo:"foo"}])
|> yield(name: "foo")

Hi @Anaisdg,

Thanks for your reply.
Unfortunately, the Flux script you suggested is not working, the same error pops out :frowning:
Yes, I’m using an all-access token, I’ve even made a new one.

It will be great to use CLI but I simply can’t get it to work.
I’ve downloaded it and followed the instruction from here: Install and use the influx CLI | InfluxDB OSS 2.3 Documentation
But when I open it, instead of opening a CLI interface it simply does nothing.

Cheers,

Hello @Cristian_Bertulli,
What version of InfluxDB are you using?
What OS are you running?
A CLI interface won’t automatically pop. For example with macOS you have to type influx in the terminal after installing the InfluxDB CLI in order to use the InfluxDB CLI.

1 Like

InfluxDB v2.3.0+SNAPSHOT.090f681737
Windows 10 Pro (64bit)

I don’t know how but now CLI is working :thinking: :expressionless:

I tried the delete command but it seems I have difficulties with parsing time :sweat_smile:

influx delete --bucket Test12 --start '2022-06-30T18:00:00.999999999Z07:00' --stop '2022-07-03T00:00:00.999999999Z07:00' --predicate '_measurement="R12_WD"'
Error: start time "'2022-06-30T18:00:00.999999999Z07:00'" cannot be parsed as RFC3339Nano: parsing time "'2022-06-30T18:00:00.999999999Z07:00'" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "'2022-06-30T18:00:00.999999999Z07:00'" as "2006"

I tried with 2022-06-30T18:00:00Z or 2022-06-30T18:00:00.00Z or 2022-06-30T18:00:00.000Z but the same error message pops up.

Cheers and thanks for the help

@Cristian_Bertulli,
Can you please try copy and pasting:

influx delete --bucket Test12 \
  --start '2020-06-30T18:00:00Z' \
  --stop '2020-07-03T00:00:00Z' \
  --predicate '_measurement="R12_WD"'

I tried to copy-paste into the Prompt but it takes line per line so it ends up with error

Error: Required flags "start, stop" not set

So I tried to write it manually, but it says Error: unknown command "\\" for "delete"

I must be missing something very simple here, so forgive me for my silly question.
What is the difference between what you wrote

and

influx delete --bucket Test12 --start '2022-06-30T18:00:00Z' --stop '2022-07-03T00:00:00Z' --predicate '_measurement="R12_WD"'

besides the year ( which is 2022, I wrote it wrong the first time ).

Thanks a lot for the help :muscle: and sorry for taking so much time :sweat_smile:

Hello @Cristian_Bertulli,
If you copy and past the entire chunk including the back slashes it includes a line continuation. And you shouldn’t get that error. What OS are you using?

Otherwise you can do:

influx delete --bucket Test12  --start '2020-06-30T18:00:00Z' --stop '2020-07-03T00:00:00Z' --predicate '_measurement="R12_WD"'

I’ve tried all the possible DateTime formats but still the same error " Cannot be parsed ad RFC3339Nano "

Cheers and thanks :grinning:

I’m very late finding this thread, but anyone else who comes across it - I believe the answer to the problem here is that you must execute through powershell. If you use a windows CLI it’ll produce the above error. I suspect it has to do with date interpretation in each CLI … but I haven’t bothered to do more than reproduce the problem in standard CLI, and watch it work in powershell.

Cheers.

1 Like