workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: A request to the Cloudflare API (/memberships) failed. [code: 9109]

Open edmooney opened this issue 3 years ago • 12 comments
trafficstars

What version of Wrangler are you using?

2.0.16

What operating system are you using?

Linux (Manjaro)

Describe the Bug

Steps 1-3 work fine per: https://developers.cloudflare.com/pub-sub/get-started/guide/ - validated the pubsub token - "This API Token is valid and active". exported the token variable to the console. and verified that the token has all account access with Editing rights.

However get the following message when creating a namespace:

   ~  wrangler pubsub namespace create thenamespacename  ✔

✘ [ERROR] A request to the Cloudflare API (/memberships) failed.

Unauthorized to access requested resource [code: 9109]

If you think this is a bug, please open an issue at: https://github.com/cloudflare/wrangler2/issues/new/choose

edmooney avatar Jul 06 '22 17:07 edmooney

What account ID is this associated with?

I can't reproduce this with a valid, Pub/Sub only API Token.

elithrar avatar Jul 06 '22 18:07 elithrar

Also seeing this on a new wrangler setup for a worker. I see it flash on the npx wrangler login prompt for a half second

qbunt avatar Jul 06 '22 19:07 qbunt

I had upgraded wrangler, re-authenticated with wrangler login. account id: 9afa0a18632286ba47d3e1da53bb20e5

edmooney avatar Jul 06 '22 21:07 edmooney

Test with new key - 07/09/2022-12:20 AM EST Generated new key... with Edit rights for pubsub in all accounts - API test curl test with new key:

   ~  curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \  1 ✘ -H "Authorization: Bearer [btoken-here]
-H "Content-Type:application/json"

{"result":{"id":"f408bbc6b902a7c0a9c68b328279b9a5","status":"active"},"success":true,"errors":[],"messages":[{"code":10000,"message":"This API Token is valid and active","type":null}]}%


wrangler pubsub namespace create [namespace-name] Retrieving cached values for account from node_modules/.cache/wrangler Creating Pub/SubNamespace [namespace-name] ...

✘ [ERROR] A request to the Cloudflare API (/accounts/9afa0a18632286ba47d3e1da53bb20e5/pubsub/namespaces) failed.

Pubsub not enabled [code: 2007]

If you think this is a bug, please open an issue at: https://github.com/cloudflare/wrangler2/issues/new/choose

edmooney avatar Jul 09 '22 16:07 edmooney

I'm facing the same issue after upgrading from 2.0.14 to 2.0.21.

$ wrangler publish --env=beta
 ⛅️ wrangler 2.0.21 
--------------------

✘ [ERROR] A request to the Cloudflare API (/memberships) failed.

  Invalid request headers [code: 6003]
  - Invalid format for X-Auth-Key header [code: 6103]

I tried to re-login but it doesn't help. Reverting back to 2.0.14 fixes the issue.

kombucha avatar Jul 15 '22 17:07 kombucha

@kombucha - in your case it looks like Wrangler is trying to use a global API key that you are providing. The ability to do this was added after 2.0.14. Do you have the CLOUDFLARE_API_KEY or CF_API_KEY environment variable set? If so, can you check that this is a valid key?

petebacondarwin avatar Jul 18 '22 08:07 petebacondarwin

@petebacondarwin indeed I had an invalid CLOUDFLARE_API_KEY value in my environment variables from a long time ago. Removing it solved the issue for me. Thank you!

kombucha avatar Jul 18 '22 11:07 kombucha

I'm using https://github.com/cloudflare/wrangler-action to publish worker in GitHub Actions and I meet the same problem.

Using API Token authentication
$ Running: wrangler publish --env prod
 ⛅️ wrangler 2.0.21 (update available 2.0.[22])
---------------------------------------------
✘ [ERROR]A request to the Cloudflare API (/memberships) failed.
  Unauthorized to access requested resource [code: 9109]
  If you think this is a bug, please open an issue at: https://github.com/cloudflare/wrangler2/issues/new/choose

the key is created by Edit Cloudflare Workers: CleanShot 2022-07-19 at 13 33 11@2x

bytemain avatar Jul 19 '22 05:07 bytemain

@bytemain - when you created this API token from the template, did you restrict the token to only one Zone?

petebacondarwin avatar Jul 19 '22 08:07 petebacondarwin

I'm using:

All accounts, [email protected], All zones

CleanShot 2022-07-19 at 16 23 27@2x

but it still throw this error...

bytemain avatar Jul 19 '22 08:07 bytemain

A workaround to this issue is to add an account_id in your wrangler.toml, or set it as an environment variable with CLOUDFLARE_ACCOUNT_ID. We could probably add this tip in the error message itself.

threepointone avatar Jul 19 '22 19:07 threepointone

I also just had this issue (wrangler 2.0.23) with an older project. (Re-)adding the account_id to wrangler.toml worked.

But it's unclear that this is required, especially because a recent project created with Wrangler 2 doesn't require this.

marcelduin avatar Jul 27 '22 23:07 marcelduin

Addressed in #1683

JacobMGEvans avatar Aug 15 '22 15:08 JacobMGEvans