Cloudflare_token

For Workers & Pages, what is the name of the domain?

example.com

What is the error number?

9109

What is the error message?

“Unauthorized to access requested resource”

What is the issue or error you’re encountering

I am trying to create a scoped credential for a r2 bucket using boto3. I can create the scoped token using headers = {“X-Auth-Email”: X_AUTH_EMAIL, “X-Auth-Key”: X_AUTH_KEY, “Content-Type”: “application/json”} but the same cannot be done using the headers = {“Authorization”: f"Bearer {CLOUDFLARE_TOKEN}", “Content-Type”: “application/json” }

What steps have you taken to resolve the issue?

I tried generating the token from Manage API Token section and from my Profile → API Token.

What are the steps to reproduce the issue?

API Headers

headers = {
“Authorization”: f"Bearer {CLOUDFLARE_TOKEN}“,
“Content-Type”: “application/json”
}
data = {
“name”: token_name,
“policies”: [
{
“effect”: “allow”,
“permission_groups”: [
{
“id”: CLOUDFLARE_PERMISSION_GROUP
}
],
“resources”: {
f”{CLOUDFLARE_RESOURCE_URL}.{CLOUDFLARE_ACCOUNT_ID}{CLOUDFLARE_JURISDICTION}{bucket_name}": “*”
}
}
],
“condition”: {},
“not_before”: None,
“expires_on”: None
}

response = requests.post(
url=CLOUDFLARE_SCOPED_TOKEN_CREATION_URL,
headers=headers,
data=json.dumps(data)
)