Using legacy API: v1 -> v2 & mapping?

Good day

I am attempting to use InfluxDB legacy API because InfluxDB 2 currently lacks support for daily aggregation with timezones; however it appears that InfluxQL supports it.

I created a mapping, which is visible when I call GET http://192.168.0.4:8086/api/v2/dbrps?org=REI&db=REI . Output:

{
    "content": [
        {
            "id": "07b8cfe5bce66000",
            "database": "REI",
            "retention_policy": "REI",
            "default": true,
            "orgID": "0f94c085ced68da4",
            "bucketID": "73cf757cef16b058"
        }
    ]
}

However, when I call GET http://192.168.0.4:8086/query?db=REI&q=SELECT%20used_percent%20FROM%20REI.REI.load_profile_electricity, InfluxDB complains about the database being not found. Output:

{
    "results": [
        {
            "statement_id": 0,
            "error": "database not found: REI"
        }
    ]
}

Can someone please tell me what might be wrong here?
Thanks

Hello @Alexander_Savinykh,
Hmm I’m not sure. I’ll ask the InfluxDB team. Your query looks good and your mapping looks successful to me.
Also you can use offset with window() or aggregateWindow() to convert for tz.
https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/window/

Hello @Alexander_Savinykh,
Is it possible that you created the mapping but not the bucket?
Have you followed this documentation?
https://docs.influxdata.com/influxdb/cloud/reference/api/influxdb-1x/query/
https://docs.influxdata.com/influxdb/cloud/query-data/influxql/

Thanks for the response. Using aggregateWindows & offset seems possible only within the time range where time zone offset stays the same; however it might be different because of daylight time savings

The mapping is created for an existing bucket. If I try to specify a non-existing bucket id then I get an error immediately from creating the mapping

Are you using the same token to create the dbrp mapping as when accessing the bucket? What permissions do the token(s) have (eg, all access, org buckets, scoped buckets, something else)? What version of influxdb are you using?

I am using admin’s token (the 1st user you create when logging in to InfluxDB 2 Web UI for the first time)

I got it to work using user mapping created by command influx v1 auth create (this way, the data can be accessed with u= username and p= password)

This is less convenient than using API access token, however I will use this approach if I cannot find a way to make it work with API access token

@Alexander_Savinykh as far as I know, the solution you found (creating & using a v1 auth) is the only way to make it work

1 Like

When using the token, are you specifying the header correctly? Eg, with curl you would use curl ... -H "Authorization: Token <your token here>" ...?

Yes. I can verify that by temporarily removing header Authorization: ... from the request. If I do that, then I get a different error: “unauthorized access” instead of “database not found”

as far as I know, the solution you found (creating & using a v1 auth ) is the only way to make it work

I can say that if I create the dbrp with the admin token, I am able to perform v1 queries against OSS 2.0.4 with a bucket-scoped token created in UI with the following:

# create the mapping with admin token
$ curl --insecure -H "Authorization: Token $TOKEN_ADMIN" --request POST "$URL/api/v2/dbrps" --data "{\"orgID\":\"$ORGID\", \"bucketID\":\"$BUCKETID\", \"database\":\"REI\", \"retention_policy\": \"REI\"}"

# do the query with a ui-generated read/write scoped bucket token
$ curl --insecure -H "Authorization: Token $TOKEN" --request GET "$URL/query?db=REI&q=SELECT%20*%20FROM%20REI.REI.cpu"

I can also do the v1 query with the admin token (not shown). I haven’t been able to reproduce the issue with 2.0.4…