Permissions Needed and Correct API Command for Billing Item Access

Hello All-

I am trying to access our billing information using the Cloudflare API to dump this data for analysis in another solution.

Our network:

Company owner created his own Cloudflare account - with a mixture of different zones and levels - free pro and business zones.
Owner asks employees to create their own private Cloudflare accounts. Owner then makes us all administrators on his account.
Company moves on working this way for several years. No problems.
I administer all domains, rules, features using Cloudflare API and self-created tokens with access to owner’s account. all is well.

New requirement:
Management would like billing reports of monthly spend by vendor service with categories in each bill

For Cloudflare, goal is to download the monthly invoice or bill or list of costs and list the total spend for the past month and if possible break down spend by categories and cost of each.

Problem: Cloudflare support states that my account does not have Billing access - since it isn’t an Enterprise-level account only the owner has access via web portal or API to billing information

Solution proposed: Owner creates a limited access token for me with full billing read access in order to run the billing history command:

See this documentation: - Cloudflare won’t let me insert the link here - Under the Cloudflare API Documentation see ‘Billing History’.

He walks me through how he creates the token - anew token, full billing read access to all accounts, limited to IPs of our office and VPN networks.

We test the authentication key with the test CURL command provided with the key and it is working.

But - the billing API command is not working - I am getting an authentication error:

Command:

curl -X GET "https://api.cloudflare.com/client/v4/user/billing/history" \
>      -H "X-Auth-Email: $CLOUDFLARE_BILLING_EMAIL" \
>      -H "X-Auth-Key: $CLOUDFLARE_BILLING_TOKEN" \
>      -H "Content-Type: application/json"

Results:
{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}
Michaels-MacBook-Pro-2:~ mike$

If I use my own token and email, which would access my own personal, empty account, the command works. There is no output b/c my account has nothing in it:

Command:

curl -X GET "https://api.cloudflare.com/client/v4/user/billing/history" \
>      -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
>      -H "X-Auth-Key: $CLOUDFLARE_TOKEN" \
>      -H "Content-Type: application/json"

Results:
{“errors”:,“messages”:,“result”:,“result_info”:{“page”:1,“per_page”:50,“next_page”:false},“success”:true}

I opened a support ticket for this with Cloudflare support but b/c we are not an enterprise account holder it may be several days before I hear a response - or not at all.

My question:

1 Does anyone know if this documentation is correct, and all I need to read the billing info is “billing read” rights on the account?

See this documentation: - Cloudflare won’t let me insert the link here - Under the Cloudflare API Documentation see ‘Billing History’.

  1. Am I running this command correctly?
curl -X GET "https://api.cloudflare.com/client/v4/user/billing/history" \
     -H "X-Auth-Email: $CLOUDFLARE_BILLING_EMAIL" \
     -H "X-Auth-Key: $CLOUDFLARE_BILLING_TOKEN" \
     -H "Content-Type: application/json"

3, Can anyone recommend a better way to return the billing items for a data range, such as the previous month, perhaps using a different account?

Thanks!

Mike

Don’t know if this has been solved yet, but the first thing that stands out is that you are using X-Auth-Email and X-Auth-Key. There are two ways of authenticating with the API, the X-AUTH headers use the Global API key and not an API token. What you want is something like

curl -X GET "https://api.cloudflare.com/client/v4/user/billing/history" \
     -H "Authorization: Bearer $CLOUDFLARE_BILLING_TOKEN" \
     -H "Content-Type: application/json"

. It might also be looking at subscriptions as well as billing

Account Subscriptions
User Subscriptions
Zone Subscriptions

1 Like

Thank you Cyb3r-Jak3 - that worked!

Do you know if there is an API call I can run to get a line-item breakdown of a bill or invoice?

Thanks!

Mike

I believe that when this last came up, there isn’t an API method for getting a break-down or generating an invoice. The only way to view a line by line breakdown is viewing the PDF.