Influx delete API in golang

Hell All,

I am new to influx and using influx APIs in golang. I want to learn how to call the delete APIs in golang for deleting data in influx db.
Any link/sample programs will be much appreciated.

Hello @teenccu,
Welcome! What version of InfluxDB are you using?
Here are the API docs:

Here’s an example:

package main

import (
    "bytes"
    "net/http"
)

func main() {
    url := "http://localhost:8086/api/v2/delete?org=example-org&bucket=example-bucket"
    var jsonData = []byte(`
    {
        "start": "2020-03-01T00:00:00Z",
        "stop": "2020-11-14T00:00:00Z",
        "predicate": "_measurement=\"example-measurement\" AND exampleTag=\"exampleTagValue\""
    }`)

    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    if err != nil {
        panic(err)
    }

    req.Header.Set("Authorization", "Token YOUR_API_TOKEN")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    // Handle the response here, e.g., read resp.Body or check resp.StatusCode
}

Hello Anaisdg,

Thanks for your response. I am using V2. so thanks for providing the example .
For the moment I am using the GoLang APIs for treating the data
import (
influxdb2 “github.com/influxdata/influxdb-client-go/v2
)

and I have seen there is a deleteAPI provided like
deleteAPI := client.DeleteAPI()

Is it recommended to use that and any example on these APIs ?

Thanks in advance.

Hello @Anaisdg ,

I tried to see the golang API and relate it with your example and I think I can understand it.

I have not tried it yet as I need to reolve another question as posted in
(Read/Delete data with a specific time in golang)

Thanks for your help.