# InfluxDB v2 API - Authorization not found writing to bucket

**URL:** <https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709>\
**Category:** InfluxDB 2\
**Tags:** influxdb\
**Created:** [February 4, 2022, 10:27pm UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709 "2022-02-04T22:27:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crockk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/crockk/32/9417_2.png) [@crockk](https://community.influxdata.com/u/crockk)\
**Post date:** [February 4, 2022, 10:27pm UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709/1 "2022-02-04T22:27:15Z")

</div>

Hello, I am relatively new to InfluxDB but I have been having issues authenticating with the API. I am referring to the [API documentation](https://docs.influxdata.com/influxdb/v2.0/api/#operation/PostWrite) to properly authenticate and write to my bucket. I scoped an API token with Read/Write access for the bucket I am writing to.

The API token information is as follows (sensitive info removed from all code snippets, retrieved from calling `/api/v2/authorizations`):

```auto
{
  "id": "08dda35eb66d4000",
  "token": "xxxx_xxxxxxxxxxx_xxxxxx_xxxxx==",
  "status": "active",
  "description": "Veeam Bucket R/W",
  "orgID": "0dda9e31682bab19",
  "org": "MY ORG",
  "userID": "08dd9356202d4000",
  "user": "veeam",
  "permissions": [
          {
                  "action": "read",
                  "resource": {
                          "type": "buckets",
                          "id": "67cba1fb1f2723df",
                          "orgID": "0dda9e31682bab19",
                          "name": "Veeam",
                          "org": "MY ORG"
                  }
          },
          {
                  "action": "write",
                  "resource": {
                          "type": "buckets",
                          "id": "67cba1fb1f2723df",
                          "orgID": "0dda9e31682bab19",
                          "name": "Veeam",
                          "org": "MY ORG"
                  }
          }
  ],
  "links": {
          "self": "/api/v2/authorizations/08dda35eb66d4000",
          "user": "/api/v2/users/08dd9356202d4000"
  },
  "createdAt": "2022-02-04T21:07:18.873073786Z",
  "updatedAt": "2022-02-04T21:07:41.78886211Z"
}
]

```

My user is (retrieved from `/api/v2/users/{userid}`)

```auto
{
        "links": {
                "self": "/api/v2/users/08dd9356202d4000"
        },
        "id": "08dd9356202d4000",
        "name": "veeam",
        "oauthID": "xxx",
        "status": "active"
}

```

My org is (`/api/v2/orgs/{orgid}`):

```auto
{
        "links": {
                "buckets": "/api/v2/buckets?org=MY ORG",
                "dashboards": "/api/v2/dashboards?org=MY ORG",
                "labels": "/api/v2/orgs/0dda9e31682bab19/labels",
                "logs": "/api/v2/orgs/0dda9e31682bab19/logs",
                "members": "/api/v2/orgs/0dda9e31682bab19/members",
                "owners": "/api/v2/orgs/0dda9e31682bab19/owners",
                "secrets": "/api/v2/orgs/0dda9e31682bab19/secrets",
                "self": "/api/v2/orgs/0dda9e31682bab19",
                "tasks": "/api/v2/tasks?org=MY ORG"
        },
        "id": "0dda9e31682bab19",
        "name": "MY ORG",
        "description": "",
        "createdAt": "2022-01-29T00:27:01.998959549Z",
        "updatedAt": "2022-01-29T00:27:01.998961565Z"
}

```

Finally, my bucket to write to is (`/api/v2/buckets/{bucketid}`):

```auto
{
        "id": "67cba1fb1f2723df",
        "orgID": "0dda9e31682bab19",
        "type": "user",
        "name": "Veeam",
        "retentionRules": [
                {
                        "type": "expire",
                        "everySeconds": 2592000,
                        "shardGroupDurationSeconds": 86400
                }
        ],
        "createdAt": "2022-01-29T00:31:40.693599432Z",
        "updatedAt": "2022-01-29T00:31:40.693601537Z",
        "links": {
                "labels": "/api/v2/buckets/67cba1fb1f2723df/labels",
                "members": "/api/v2/buckets/67cba1fb1f2723df/members",
                "org": "/api/v2/orgs/0dda9e31682bab19",
                "owners": "/api/v2/buckets/67cba1fb1f2723df/owners",
                "self": "/api/v2/buckets/67cba1fb1f2723df",
                "write": "/api/v2/write?org=0dda9e31682bab19\u0026bucket=67cba1fb1f2723df"
        },
        "labels": []
}

```

I have a curl request for sending Veeam data back to my InfluxDB:

```auto
veeamInfluxDBURL="http://localhost"
veeamInfluxDBPort="8086"
veeamInfluxBucketID="67cba1fb1f2723df"
veeamInfluxDBOrgID="0dda9e31682bab19"
veeamInfluxDBToken="xxxx_xxxxxxxxxxx_xxxxxx_xxxxx=="

curl -i -X POST "$veeamInfluxDBURL:$veeamInfluxDBPort/api/v2/write?bucket=$veeamInfluxBucketID&org=$veeamInfluxDBOrgID&precision=s" \
  -H 'Content-type: text/plain; charset=utf-8' \
  -H 'Authorization: Token $veeamInfluxDBToken' \
  -H 'Accept: application/json' \
  --data-binary "veeam_em_overview,host=$veeamRestServer veeamBackupServers=$veeamBackupServers,veeamProxyServers=$veeamProxyServers,veeamRepositoryServers=$veeamRepositoryServers,veeamRunningJobs=$veeamRunningJobs,veeamScheduledJobs=$veeamScheduledJobs,veeamSuccessfulVmLastestStates=$veeamSuccessfulVmLastestStates,veeamWarningVmLastestStates=$veeamWarningVmLastestStates,veeamFailedVmLastestStates=$veeamFailedVmLastestStates"

```

However this results in the following 401 unauthorized response:

```auto
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
X-Influxdb-Build: OSS
X-Influxdb-Version: 2.1.1
X-Platform-Error-Code: unauthorized
Date: Fri, 04 Feb 2022 22:03:22 GMT
Content-Length: 55

{"code":"unauthorized","message":"unauthorized access"}

```

And this log on InfluxDB:

```auto
Feb 04 22:03:22 influxdb1 influxd-systemd-start.sh[164020]: ts=2022-02-04T22:03:22.678078Z lvl=info msg=Unauthorized log_id=0ZPxQVIW000 error="authorization not found"

```

I have essentially quadruple checked my bucket ID, org ID, and API Token, and I can’t figure out why it will not authenticate. Any tips would be appreciated.

---

<div class="post-metadata">

**Author:** ![jorgedlcruz](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jorgedlcruz/32/7528_2.png) [@jorgedlcruz](https://community.influxdata.com/u/jorgedlcruz)\
**Post date:** [February 7, 2022, 6:32pm UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709/2 "2022-02-07T18:32:43Z")

</div>

Hello, answered on GitHub as well, but as I can see, you are using ID, but the script says to use it like this:

```auto
veeamInfluxDBURL="http://YOURINFLUXSERVERIP" #Your InfluxDB Server, http://FQDN or https://FQDN if using SSL
veeamInfluxDBPort="8086" #Default Port
veeamInfluxDBBucket="veeam" # InfluxDB bucket name (not ID)
veeamInfluxDBToken="TOKEN" # InfluxDB access token with read/write privileges for the bucket
veeamInfluxDBOrg="ORG NAME" # InfluxDB organisation name (not ID)

```

Or, on my case for example:

```auto
veeamInfluxDBURL="https://yourinfluxserver" #Your InfluxDB Server, http://FQDN or https://FQDN if using SSL
veeamInfluxDBPort="8086" #Default Port
veeamInfluxDBBucket="telegraf" # InfluxDB bucket name (not ID)
veeamInfluxDBToken="MYLONGTOKEN" # InfluxDB access token with read/write privileges for the bucket
veeamInfluxDBOrg="Blog Jorge de la Cruz" # InfluxDB organisation name (not ID)

```

That should work

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [February 7, 2022, 6:36pm UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709/3 "2022-02-07T18:36:27Z")

</div>

Hello @crockk,  
You might also find this useful:

> **[%%title%% | InfluxData | InfluxData](https://www.influxdata.com/blog/getting-started-influxdb-2-0-api-postman/)**
>
> Today we want to share a Postman project to help you use the API easily. Postman is an API platform for building and using APIs.

---

<div class="post-metadata">

**Author:** ![crockk](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/crockk/32/9417_2.png) [@crockk](https://community.influxdata.com/u/crockk)\
**Post date:** [February 7, 2022, 10:24pm UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709/4 "2022-02-07T22:24:54Z")

</div>

As stated in [our conversation on GitHub](https://github.com/VeeamHub/grafana/issues/18#issuecomment-1030386258), I attempted this first as that was, indeed, how the script says to use it. Just to be crystal clear, here I am using your method but still getting the same authentication errors:

```auto
veeamInfluxDBOrg="My+Org" # using + for spaces, otherwise I get 400 bad request due to whitespace
veeamInfluxDB='Veeam'
veeamInfluxDBToken='xxxxxx==' # read/write token, which I have verified works with influx CLI
veeamInfluxDBURL="http://localhost" # not running behind any proxy/SSL
veeamInfluxDBPort="8086"

curl -i -X POST "$veeamInfluxDBURL:$veeamInfluxDBPort/api/v2/write?bucket=$veeamInfluxDB&org=$veeamInfluxDBOrg&precision=s" \
      -H 'Content-type: text/plain; charset=utf-8' \
      -H 'Authorization: Token $veeamInfluxDBToken' \
      -H 'Accept: application/json' \
      --data-binary "veeam_em_overview,host=$veeamRestServer veeamBackupServers=$veeamBackupServers,veeamProxyServers=$veeamProxyServers,veeamRepositoryServers=$veeamRepositoryServers,veeamRunningJobs=$veeamRunningJobs,veeamScheduledJobs=$veeamScheduledJobs,veeamSuccessfulVmLastestStates=$veeamSuccessfulVmLastestStates,veeamWarningVmLastestStates=$veeamWarningVmLastestStates,veeamFailedVmLastestStates=$veeamFailedVmLastestStates"

```

Response:

```auto
Writing veeam_em_overview to InfluxDB
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
X-Influxdb-Build: OSS
X-Influxdb-Version: 2.1.1
X-Platform-Error-Code: unauthorized
Date: Mon, 07 Feb 2022 22:16:39 GMT
Content-Length: 55

{"code":"unauthorized","message":"unauthorized access"}

```

I am not particularly interested in solving this issue any longer however, as I have switched from direct API requests to using:

```auto
influx write -b $veeamInfluxDB $DATA

```

Thanks for your time

---

<div class="post-metadata">

**Author:** ![jorgedlcruz](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jorgedlcruz/32/7528_2.png) [@jorgedlcruz](https://community.influxdata.com/u/jorgedlcruz)\
**Post date:** [February 8, 2022, 9:59am UTC](https://community.influxdata.com/t/influxdb-v2-api-authorization-not-found-writing-to-bucket/23709/5 "2022-02-08T09:59:44Z")

</div>

Ah, yes my mistake.

Appreciate a lot your time debugging this, and glad you found a workaround!

Will keep my eyes open in case somebody else reports the issue.

Feedback and ideas always welcome, take care.
