cloudflare/python-cloudflare

[Question] How to verify the API token using this library?

simkimsia opened this issue ยท 6 comments

How do I use this library to verify a token?

https://api.cloudflare.com/#user-api-tokens-verify-token This is the api endpoint with a curl example. I like to use this library to verify the given token.

something like

cf = CloudFlare.CloudFlare(token=legal_token)
cf.verify_token() # returns True
cf = CloudFlare.CloudFlare(token=illegal_token)
cf.verify_token() # returns False

can help me understand how to do this with this library?

Or a way to extract token details https://api.cloudflare.com/#user-api-tokens-token-details

Because I also want to check if the token has the right permissions.

Like all API calls you just follow the API name to create a Python call.

    cf = CloudFlare.CloudFlare(token=legal_token)
    response = cf.user.verify.token()

Then follow the information on Cloudflare's API page to see what values are returned. https://api.cloudflare.com/#user-api-tokens-verify-token

Hope that helps.

@simkimsia - I added an example to call the correct API and print the result. Please try this.

See example_user_tokens.py

Like all API calls you just follow the API name to create a Python call.

Oh i didn't know this. Perhaps you can make this more explicit somewhere in the readme or the docs.

Maybe have a section/question like

## Need an example but cannot find an appropriate one?

Like all API calls you just follow the API name to create a Python call.

so for example if you need <example-api>

you can simply do 

\`\`\`python

cf = CloudFlare.CloudFlare(token=legal_token)
response = cf.example.api()
\`\`\`

And also furnish one example that shows how to send data as part of API.

I added an example to call the correct API and print the result. Please try this

oh @mahtin thank you so much ๐Ÿ™‡๐Ÿปโ€โ™‚๏ธ

Oh i didn't know this. Perhaps you can make this more explicit somewhere in the readme or the docs.

The README links to a Cloudflare blog article from seven years ago explaining the usage of the library. I will update the README at some point in order to make that link more apparent as it answers your question directly.

While written seven years ago and, as you see, prior to the company name change, it still stands as a solid reference document.

I hope your coding is successful.

The README links to a Cloudflare blog article from seven years ago

I see it now.

Actually i skimmed the same article a few times before, but i guess i should have slowed down.

Maybe can make it easier to skim by putting a H2 that says explicitly

Converting API calls into Python command