API for "Cloudflare Image Optimization" not working

I’m trying to use curl (as instructed) to upload images

curl --request POST --url “https://api.cloudflare.com/client/v4/accounts/cc8900b63dc0e242900abe69d7ffb376/images/v1/direct_upload” --header ‘Content-Type: application/json’ --header ‘Authorization: Bearer TOKEN’

curl -X POST -F [email protected]/home/stubfeed/STUBX/4.jpg -H “Authorization: Bearer TOKEN” “https://api.cloudflare.com/client/v4/accounts/cc8900b63dc0e242900abe69d7ffb376/images/v1

I’m trying with my global token,
I’m trying with a created token " * All accounts - Cloudflare Images:Edit"

every time, I get this answer
{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}

What I’m I doing wrong ?

What step is missing ??

Global isn’t a Token, so the syntax would have to be different.

I’m a little unclear on what direct_upload requires, but API docs says it doesn’t use a key, and the syntax doesn’t use a token. Dunno about that one.

I’d say the next step is to try Global API Key again, but with the Key syntax instead of Bearer Token syntax.

I’m also trying with a created token " * All accounts - Cloudflare Images:Edit"

same error

Same error. cant find anythings in this forum to fix

@zaid Can you help us? I’m also having the same error, I’ve double-checked the Authorization (I’m using my Global API Key).

The return is: 400 - Bad Request
{
“success”: false,
“errors”: [
{
“code”: 10000,
“message”: “Authentication error”
}
]
}

Nothing like a fresh new day to debug things…

So here is the thing that I think it’s sometimes confusing to people: API Keys and Tokens are different things. So inside your header, you have two options:

  1. Use Authorization with API Token (which you will have to create and point to Cloudflare images, during the creation process)

The header will be like this:

Content-Type: application/json
Authorization: Bearer xxxxxx(your API token)

  1. Use the Global API Key (I guess the first option is best practice tho)

The header will be like this:

Content-Type: application/json
X-Auth-Email: (your Cloudflare email)
X-Auth-Key: (your global API Key)

Hope it helps!