Authentication error: invalid scope requested - Raw HTTP req to loki

Trying to send a raw http request to loki, and getthing this error “authentication error: invalid scope requested”

This is how I’m forming my request

host: https://username:token@logs-prod-006.grafana.net/loki/api/v1/push
content: some json
headers: { ['Content-Type'] = 'application/json', ["X-Scope-OrgID"] = "my_org_id_in_org_settings"})

Any idea whats going on?

Please remove X-Scope-OrgID header.

Already tried removing it, same issue unfortunately

Please provide reproducible example?

Have reproduced it with curl, using a similar example I found here: prometheus - Send logs directly to Loki without use of agents - Stack Overflow

curl -v -H "Content-Type: application/json" -XPOST -s "https://username:token@logs-prod-006.grafana.net/loki/api/v1/push" --data-raw '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}'

Try:

curl \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer username:token" \
  -X POST \
  -d '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}' \
  https://logs-prod-006.grafana.net/loki/api/v1/push

Make sure that you have write permission for used user/token.

Getting the same issue with that curl request you provided

Just to confirm I am getting the username and token from
https://grafana.com/orgs/robcf09/hosted-logs/USERNAME_HERE

There’s just a button generate the token, how do I check it has the correct write permission?
image

Generate new token and select right scope:

1 Like

Thank you :slight_smile:

My token only had logs read, needed logs write!

1 Like