Skip to main content

Get my Netlify bandwidth usage from the API

I wanted to add a little graph showing my Netlify usage to my analytics dashboard. You can see this in the Netlify dashboard, but I log in to that rarely so it’s not helpful:

A screenshot from the Netlify dashboard showing I've used 25GB of 100GB in the current period.

I used the Netlify API to get the data and show it in another dashboard.

  1. I created a personal access token in my user settings.

  2. I got my Netlify team identifier from the URL of my settings page (https://app.netlify.com/teams/<team_id>/settings/general).

  3. I called the Netlify API to get the data:

    $ curl -H 'Authorization: Bearer <TOKEN>' 'https://api.netlify.com/api/v1/accounts/<team_slug>/bandwidth' | jq .
    {
      "used": 27167800363,
      "included": 107374182400,
      "additional": 0,
      "last_updated_at": "2024-03-10T15:15:03.237+00:00",
      "period_start_date": "2024-02-17T00:00:00.000-08:00",
      "period_end_date": "2024-03-17T00:00:00.000-07:00"
    }
    

A couple of observations on the data you get back: