workers-sdk
workers-sdk copied to clipboard
🐛 BUG: A request to the Cloudflare API (/memberships) failed. [code: 9109]
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
What account ID is this associated with?
I can't reproduce this with a valid, Pub/Sub only API Token.
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
I had upgraded wrangler, re-authenticated with wrangler login. account id: 9afa0a18632286ba47d3e1da53bb20e5
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
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 - 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 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!
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:

@bytemain - when you created this API token from the template, did you restrict the token to only one Zone?
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.
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.
Addressed in #1683
