Skip to content
Notifications
Clear all

Has anyone successfully used the API to pull billing data for chargeback to departments?

1 Posts
1 Users
0 Reactions
4 Views
(@cloud_ops_learner_2)
Reputable Member
Joined: 2 months ago
Posts: 163
Topic starter   [#16061]

Hey everyone! 👋 I've been diving deep into Cloudflare One lately, especially around the Zero Trust and Gateway services. It's been fantastic for our security posture, but now finance is knocking on my door asking for departmental chargebacks. We need to split the bill!

I know there's a billing API, but I'm struggling to find clear examples on pulling usage data *per department* (like DNS queries, data filtered, etc.) in a way that maps to our internal teams. The portal shows aggregates, but we need the granular breakdown.

Has anyone successfully automated this? I'm looking for a script or Terraform/Ansible approach that can:
* Pull detailed usage data via the Cloudflare API, filtered by specific Zero Trust services.
* Attribute costs to departments (maybe using different `account_id`s or tags?).
* Output something usable for our finance system (CSV, or maybe even feed it into a cloud cost tool).

I started poking around with the `GET /accounts/{account_id}/billing/history` endpoint, but the documentation feels a bit high-level for this specific use case. I'm wondering if I need to use GraphQL for more detailed queries?

Here's a snippet of what I was trying with the REST API (using curl for simplicity):

```bash
curl -X GET "https://api.cloudflare.com/client/v4/accounts/{account_id}/billing/history"
-H "Authorization: Bearer YOUR_API_TOKEN"
-H "Content-Type: application/json"
```

But the response seems focused on invoices, not the service-level detail I need.

**My main questions:**
1. Is the granular, department-level data even available via API?
2. If so, which endpoints or GraphQL queries are you using?
3. Did you have to structure your account with sub-accounts or specific tags to make this work?

Any pointers, code snippets, or war stories would be super helpful. Trying to avoid building a manual spreadsheet process! 😅

~CloudOps


Infrastructure as code is the only way


   
Quote