Skip to content

Commit

Permalink
Add some notes on Retry-After and ETag
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwlchan committed Jun 12, 2024
1 parent 40401da commit 8b7f90d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/_til/2024/2024-02-28-get-netlify-usage-from-api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: til
date: 2024-02-28 10:15:24 +0000
date_updated: 2024-06-12 10:58:07 +0100
title: Get my Netlify bandwidth usage from the API
tags:
- netlify
Expand Down Expand Up @@ -43,3 +44,34 @@ A couple of observations on the data you get back:

* This value gets cached for a while -- in the example above, I called the API at 15:22 but the `last_updated_at` value is 15:03.
I'm not sure how often the value is updated.

## Being a responsible user of the API

* The API returns a `Retry-After` value, which is a minute after your request.
This is a clue about how often the value gets updated -- it's definitely not second-level granularity.

```console
$ curl -v -H 'Authorization: Bearer <TOKEN>' 'https://api.netlify.com/api/v1/accounts/<team_slug>/bandwidth'
< HTTP/2 200
< date: Wed, 12 Jun 2024 09:52:37 GMT
< retry-after: 2024-06-12 09:53:37 UTC
```

* The responses include an `ETag` header, which you can use to check if the value has changed since the last request:

```console
$ curl -v -H 'Authorization: Bearer <TOKEN>' 'https://api.netlify.com/api/v1/accounts/<TEAM_SLUG>/bandwidth'
< HTTP/2 200
< etag: W/"190b2e3e6d8c239bd546819b0f0b1eb9"

$ curl -v -H 'If-None-Match: W/"190b2e3e6d8c239bd546819b0f0b1eb9"' -H 'Authorization: Bearer <TOKEN>' 'https://api.netlify.com/api/v1/accounts/<TEAM_SLUG>/bandwidth'
< HTTP/2 304
```
Annoyingly, this doesn't make the API any faster -- responses still take about half a second, even if nothing has changed.

3 comments on commit 8b7f90d

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://66697276e2eaf4a66a0bf97c--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://666aa0ea4b9a65aa247a9e57--alexwlchan.netlify.app

@alexwlchan
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://alexwlchan.net as production
🚀 Deployed on https://666bf28aa29f4ee6227ed784--alexwlchan.netlify.app

Please sign in to comment.