IMD SolutionComputing LibraryShop main store

Troubleshooting

Grafana InfluxQL on InfluxDB 2 fails: use the Token header

Edge computing and IIoT Published 5 min read By IMD Solution engineering team

Short answer

On InfluxDB 2, a Grafana InfluxQL panel fails with Bad Request while the server log records Unauthorized and authorization not found: a 2.x token typed into the Basic Auth username and password fields is not recognized on the compatibility query path. Send the token in a custom Authorization header whose value is the word Token, a space and the token string, verified on InfluxDB OSS 2.0.2 with Grafana 7.3.3. The DBRP mapping is a separate checkpoint and needs no change.

On this page
  1. Read the server log, not the panel banner
  2. Why the username and token pair fails
  3. Send the token in the Authorization header
  4. Prove it with two requests
  5. Keep the mapping check separate from authentication
  6. The decision
  7. Questions asked

Grafana's Bad Request on an InfluxQL panel is only a generic symptom. The fault sits one step away, in the InfluxDB server log: an Unauthorized entry whose error field reads authorization not found. On InfluxDB 2 that text means the server did not recognize the credential at all, and the usual reason is the credential's format: a 2.x token typed into the Basic Auth username and password fields of the data source. The fix, verified on InfluxDB OSS 2.0.2 with Grafana 7.3.3, is to drop Basic Auth and send the token in a custom HTTP header whose value is the word Token, a space, then the token string. The DBRP mapping you already validated stays untouched; it is a separate checkpoint.

Read the server log, not the panel banner #

When a panel shows Bad Request, Grafana is passing along a generic client-side failure; it is not the diagnosis. Correlate the request time with the InfluxDB server log and look for an info-level Unauthorized line whose error field reads authorization not found. That pairing tells you the server never recognized the credential:

Observation What it means What to do
Panel: Bad Request Generic message passed up by Grafana Correlate the time with the server log
Log: Unauthorized The request failed authentication Check how Grafana formats the credential
Log: authorization not found The credential itself was not recognized Fix the header format below

The same authorization not found text on the Telegraf write path has a different cause chain, covered in the Telegraf-side fix for authorization not found on InfluxDB 2 (article:fix-telegraf-authorization-not-found-on-influxdb-2). The query path discussed here authenticates separately from the write path, so fixing one never fixes the other.

Why the username and token pair fails #

InfluxQL against InfluxDB 2 rides the 1.x compatibility query API, and that path recognizes exactly two credential forms: an Authorization header carrying the token with the Token scheme, or a username and password pair that is a compatibility credential created with influx v1 auth create. A 2.x token is neither. Typed into the Basic Auth password field, it does not match a compatibility password, so the server answers authorization not found — even while the same token lists your DBRP mapping without trouble. That is why a passing mapping test proves nothing about the query path.

The write side has the mirror-image trap, a v1 output sending Basic Auth at a 2.x server and failing the same way, covered in why the Telegraf 401 comes from the v1 output on InfluxDB 2.

Send the token in the Authorization header #

Fix the data source:

  1. Open the InfluxDB data source whose query language is set to InfluxQL.
  2. Switch off Basic Auth and clear the username and token you typed into those two fields.
  3. Add a custom header with the key Authorization.
  4. Set its value to Token <token>: the word Token with a capital T, which is case-sensitive, exactly one space, then the token string.
  5. Save and re-run the panel query; data should return and the log should gain no new Unauthorized line.

Scope that token to read the buckets behind the dashboards; the query path needs no write permission.

Prove it with two requests #

You can reproduce and fix the fault before touching Grafana. The example uses a host at 192.168.1.50 (substitute your own instance; the bracketed port stands for the port it listens on), an example database plcdata — the database name of the DBRP mapping — an example measurement line_speed, and EXAMPLE_TOKEN as a stand-in for your token:

# 1. Fails: the token sent as a Basic Auth password
curl -G "http://192.168.1.50:<port>/query" \
 --data-urlencode "db=plcdata" \
 --data-urlencode "q=SELECT last(value) FROM line_speed" \
 -u "anyuser:EXAMPLE_TOKEN"

# 2. Works: the same token in the Authorization header
curl -G "http://192.168.1.50:<port>/query" \
 --data-urlencode "db=plcdata" \
 --data-urlencode "q=SELECT last(value) FROM line_speed" \
 -H "Authorization: Token EXAMPLE_TOKEN"

Request 1 returns an Unauthorized (401) response and adds a fresh authorization not found line to the log — the reported symptom reproduced. Request 2 returns a JSON body with the last line_speed value and its timestamp, and the log stays clean. Same endpoint, same token, only the credential format differs: that is the test that proves the fix.

Keep the mapping check separate from authentication #

The DBRP mapping maps a 1.x database and retention policy pair onto a 2.x bucket, and InfluxQL on 2.x cannot run without it; the steps are in DBRP mapping configuration for Grafana InfluxQL. It is still a second, independent checkpoint:

  • Mapping: request the mapping list with your token and confirm the pair, for example database plcdata onto your bucket, is present.
  • Authentication: the query request must arrive with the Authorization header in Token form, as proven above.

A mapping that lists correctly says nothing about the header, and a correct header says nothing about the mapping. Fix the header while the log says authorization not found; only when the log is clean and the panel still returns nothing do you check that the query's database name matches the mapping.

The decision #

  • The log says authorization not found: the credential format is wrong. Remove Basic Auth, add the Authorization: Token <token> header, and the query path is repaired.
  • The client cannot send custom headers: create a compatibility username and password with influx v1 auth create and use that pair instead; a token in the password field will never authenticate on this path.
  • Header fixed, log clean, panel still empty: the fault is downstream — the mapping or the database name in the query — not authentication.
  • Dashboards written for InfluxDB 1.x: keep InfluxQL. The mapping exists so those panels run against 2.x buckets; do not rewrite them in Flux to escape an authentication error.

Questions asked

Is the Token prefix case-sensitive in the Authorization header?

Yes. The value must begin with the word Token with a capital T, followed by exactly one space and the token string. Writing bearer in place of Token, or a lowercase token, reproduces the authorization not found failure, so treat the scheme word as fixed text, not a label.

Does this fix apply to newer Grafana and InfluxDB releases?

The documented case is InfluxDB OSS 2.0.2 with Grafana 7.3.3, and the same header fix is reported for InfluxDB 2.0.3 with Grafana 8.3.3. Grafana's current troubleshooting documentation still tells InfluxQL users on InfluxDB 2.x to verify that the token sits in an Authorization header with the Token prefix, so apply the same setting on later releases.

Should I rewrite my dashboards in Flux instead?

No. Dashboards built for InfluxDB 1.x keep working through the DBRP mapping, which exists so InfluxQL queries run against 2.x buckets. Changing query language to dodge an authentication error would rewrite every panel for nothing; fix the header and keep the dashboards as they are.

Why do older guides show Basic Auth working?

Those guides target InfluxDB 1.x, where a username and password is the native scheme. On 2.x the InfluxQL path rides the 1.x compatibility API, which accepts either the Token header or a compatibility username and password created with the influx v1 auth create command, never a token typed into the password field.

Keep reading

  • Troubleshooting

    Fix Telegraf authorization not found on InfluxDB 2

    authorization not found every 10 s means InfluxDB 2 is receiving Telegraf's writes and rejecting the token: the Windows service never saw INFLUX_TOKEN set in a separate CMD session, and token = "$INFLUX_TOKEN" is not the documented substitution form. Reference the variable as "${INFLUX_TOKEN}", deliver its value in the service's startup environment, restart, and confirm the Unauthorized lines stop and the bucket fills.

    Edge computing and IIoT

  • Troubleshooting

    Troubleshoot missing data in a Node-RED InfluxDB Grafana stack

    Work the chain in order: acquisition into Node-RED, the InfluxDB service and its storage mount, the write settings, then the Grafana query. In a 2.x stack most empty panels trace to a wrong token, bucket, URL or a controller clock that stamps points outside the panel's time range.

    Edge computing and IIoT

  • How-to

    Connect Node-RED to InfluxDB 2.6 with the v2 API

    Yes: node-red-contrib-influxdb writes to InfluxDB 2.6 over the v2 API. Set the configuration node to 2.0, enter the server URL and API token, then the organization and bucket, and confirm with one controlled test write that shows up in a query against that bucket.

    Edge computing and IIoT

Historian SQL vValue exclusion filter fails: use a subquery