Signed-off-by: Meredith Lancaster <malancas@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Anne-Marie <102995847+am-stead@users.noreply.github.com> Co-authored-by: Felicity Chapman <felicitymay@github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Laura Coursen <lecoursen@github.com> Co-authored-by: AlonaHlobina <54394529+AlonaHlobina@users.noreply.github.com> Co-authored-by: Isaac Brown <101839405+isaacmbrown@users.noreply.github.com> Co-authored-by: Jules <19994093+jules-p@users.noreply.github.com> Co-authored-by: Siara <108543037+SiaraMist@users.noreply.github.com> Co-authored-by: Kelly Arwine <kellyarwine@github.com> Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com> Co-authored-by: Jon Janego <jonjanego@github.com> Co-authored-by: Jules Porter <jules-p@users.noreply.github.com> Co-authored-by: hubwriter <hubwriter@github.com> Co-authored-by: Laurenzo <lsto@github.com> Co-authored-by: Sam Browning <106113886+sabrowning1@users.noreply.github.com> Co-authored-by: Vanessa <vgrl@github.com> Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com> Co-authored-by: Claire W <78226508+crwaters16@users.noreply.github.com> Co-authored-by: Felix Guntrip <guntrip@github.com> Co-authored-by: James Fletcher <42464962+jf205@users.noreply.github.com> Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com> Co-authored-by: Tim Rogers <timrogers@github.com> Co-authored-by: docs-bot <77750099+docs-bot@users.noreply.github.com> Co-authored-by: Guillaume Perrot <guperrot@github.com> Co-authored-by: Mark Tareshawty <tarebyte@github.com> Co-authored-by: Hirsch Singhal <1666363+hpsin@users.noreply.github.com> Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com> Co-authored-by: Sunbrye Ly <56200261+sunbrye@users.noreply.github.com> Co-authored-by: PJ Quirk <pjquirk@github.com> Co-authored-by: Steve Ward <steveward@github.com> Co-authored-by: Sarita Iyer <66540150+saritai@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: SiaraMist <siaramist@github.com> Co-authored-by: Tomoko Tanaka <28242405+tallzeebaa@users.noreply.github.com> Co-authored-by: a1exmozz <187176404+a1exmozz@users.noreply.github.com> Co-authored-by: Meredith Lancaster <malancas@users.noreply.github.com> Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com> Co-authored-by: Andy Barnes <kurgol@github.com> Co-authored-by: Sheena Ganju <sheenyg@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sydney Wilson <86739163+swilson15@users.noreply.github.com> Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> Co-authored-by: Vimala Moger <166641453+VimalaMoger@users.noreply.github.com> Co-authored-by: Sharra-writes <sharra-writes@github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jenni C <97056108+dihydroJenoxide@users.noreply.github.com> Co-authored-by: Greg Mondello <72952982+gmondello@users.noreply.github.com> Co-authored-by: Mia Arts <107727642+its-mia@users.noreply.github.com> Co-authored-by: sunbrye <sunbrye@github.com> Co-authored-by: Lorenz Vanthillo <lorenz.vanthillo@gmail.com> Co-authored-by: Eboni <32157169+EboniLM@users.noreply.github.com> Co-authored-by: Junko Suzuki <pnsk@github.com> Co-authored-by: Alex Nguyen <150945400+nguyenalex836@users.noreply.github.com> Co-authored-by: heiskr <1221423+heiskr@users.noreply.github.com> Co-authored-by: Patrick Knight <patrick-knight@github.com> Co-authored-by: T. Greg Doucette <58960990+LawDevNull@users.noreply.github.com> Co-authored-by: Evan Bonsignori <ebonsignori@github.com> Co-authored-by: Robert Justin Monzingo <robertjmonzingo@gmail.com> Co-authored-by: John Coleman <thenewcoke@gmail.com> Co-authored-by: Brendan Scott-Smith <117171930+bss-mc@users.noreply.github.com> Co-authored-by: Chad Bentz <1760475+felickz@users.noreply.github.com> Co-authored-by: Justin Alex <1155821+jusuchin85@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: azenMatt <7584089+azenMatt@users.noreply.github.com> Co-authored-by: Felix Guntrip <stevecat@github.com> Co-authored-by: timrogers <116134+timrogers@users.noreply.github.com> Co-authored-by: John Clement <70238417+jclement136@users.noreply.github.com> Co-authored-by: vaindil <vaindil@github.com> Co-authored-by: Matthew Isabel <matthewisabel@github.com> Co-authored-by: Matthew Isabel <matthew.isabel@gmail.com>
10 KiB
title, intro, shortTitle, redirect_from, versions, topics, permissions, product, contentType
| title | intro | shortTitle | redirect_from | versions | topics | permissions | product | contentType | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Automating usage reporting with the REST API | Learn how to automate reporting on your use of paid features using the REST API. | Automate usage reporting |
|
|
|
Enterprise owners, organization owners, and billing managers | {% data reusables.billing.enhanced-billing-platform-product %} | tutorials |
You can automatically pull data from {% data variables.product.github %} to populate the business systems you use to monitor costs and usage using the REST API. If you haven't used the {% data variables.product.github %} REST API before, see AUTOTITLE.
Overview of endpoints
You need to use different endpoints to gather data depending on your account type and the information level you want.
{% rowheaders %}
| Account | Report | Access | Endpoint | More information |
|---|---|---|---|---|
| Users | Usage data for all paid products | Account holder | /users/{username}/settings/billing/usage |
AUTOTITLE |
| Organizations | Premium request consumption, with details of quota and billed usage | Organization owners and billing managers | /organizations/{org}/settings/billing/premium_request/usage |
AUTOTITLE |
| Organizations | Usage data for all paid products | Organization owners and billing managers | /organizations/{org}/settings/billing/usage |
AUTOTITLE |
| Enterprises | Premium request consumption, with details of quota and billed usage | Enterprise owners and billing managers | /enterprises/{enterprise}/settings/billing/premium_request/usage |
AUTOTITLE |
| Enterprises | Usage data for all paid products | Enterprise owners and billing managers | /enterprises/{enterprise}/settings/billing/usage |
AUTOTITLE |
{% endrowheaders %}
Getting premium request consumption
-
Authenticate with {% data variables.product.github %} with one of the following methods:
- {% data variables.product.prodname_cli %}: use the
gh auth logincommand to authenticate, see AUTOTITLE. - Create a {% data variables.product.pat_v1 %}: and pass the token to in your API call, see Creating a {% data variables.product.pat_v1 %}.
- {% data variables.product.prodname_cli %}: use the
-
Call the required
premium_request/usageendpoint, specifying the enterprise, organization, or user that you want data for.
Getting usage data for all paid products
-
Authenticate with {% data variables.product.github %} with one of the following methods:
- {% data variables.product.prodname_cli %}: use the
gh auth logincommand to authenticate, see AUTOTITLE. - Create a {% data variables.product.pat_v1 %}: and pass the token to in your API call, see Creating a {% data variables.product.pat_v1 %}.
- {% data variables.product.prodname_cli %}: use the
-
Call the required
usageendpoint, specifying the enterprise, organization, or user that you want data for. -
By default, data for all products for the current year is reported. For enterprises, only data that is not associated with a cost center is reported.
You can request more specific data using query parameters.
- Specify time period by setting one or more of the following parameters:
year,month,day, andhour. - Specify a cost center to report on by identifier using the
cost_center_idquery parameter (enterprise endpoint only).
- Specify time period by setting one or more of the following parameters:
For more detailed information and an example calls and responses, see:
- Get billing usage report for an enterprise
- Get billing usage report for an organization
- Get billing usage report for a user
Migrating from the endpoints used for the previous billing platform
After you transition to metered billing, the endpoints you used to get data from the previous billing platform will no longer return accurate usage information.
- Upgrade all calls of the form:
/ACCOUNT-TYPE/NAME/settings/billing/PRODUCT - To use the equivalent:
/ACCOUNT-TYPE/NAME/settings/billing/usageendpoint
Changes in authentication
If you used a {% data variables.product.pat_v2 %} to authenticate with the previous endpoints, you will need create a {% data variables.product.pat_v1 %} to authenticate with the new endpoint.
In addition, you may want to use the new query parameters to specify a time period or cost center.
Calculating {% data variables.product.prodname_actions %} information from the new response data
Example of the previous response
{"total_minutes_used": 305, "total_paid_minutes_used": 0, "included_minutes": 3000, "minutes_used_breakdown": { "UBUNTU": 205, "MACOS": 10, "WINDOWS": 90 } }
Example of the new response
{ "usageItems": [ { "date": "2023-08-01", "product": "Actions", "sku": "Actions Linux", "quantity": 100, "unitType": "minutes", "pricePerUnit": 0.008, "grossAmount": 0.8, "discountAmount": 0, "netAmount": 0.8, "organizationName": "GitHub", "repositoryName": "github/example"} ] }
To get the same values from the new response data:
{% rowheaders %}
| Previous property | Calculate from new API response |
|---|---|
total_minutes_used |
|
total_paid_minutes_used |
This is now represented as a $ amount via netAmount.
|
included_minutes |
This is now represented as a $ amount via discountAmount.
|
minutes_used_breakdown |
|
{% endrowheaders %}
Calculating {% data variables.product.prodname_registry %} information from the new response data
Example of the previous response
{ "total_gigabytes_bandwidth_used": 50, "total_paid_gigabytes_bandwidth_used": 40, "included_gigabytes_bandwidth": 10 }
Example of the new response
{ "usageItems": [ { "date": "2023-08-01", "product": "Packages", "sku": "Packages data transfer", "quantity": 100, "unitType": "gigabytes", "pricePerUnit": 0.008, "grossAmount": 0.8, "discountAmount": 0, "netAmount": 0.8, "organizationName": "GitHub", "repositoryName": "github/example" } ] }
{% rowheaders %}
| Previous property | Calculate from new API response |
|---|---|
total_gigabytes_bandwidth_used |
|
total_paid_gigabytes_bandwidth_used |
This is now represented as a $ amount via netAmount.
|
included_gigabytes_bandwidth |
This is now represented as a $ amount via discountAmount.
|
{% endrowheaders %}
Calculating shared storage information from the new response data
Example of the previous response
{ "days_left_in_billing_cycle": 20, "estimated_paid_storage_for_month": 15, "estimated_storage_for_month": 40 }
Example of the new response
{ "usageItems": [ { "date": "2023-08-01", "product": "Packages", "sku": "Packages storage", "quantity": 100, "unitType": "GigabyteHours", "pricePerUnit": 0.008, "grossAmount": 0.8, "discountAmount": 0, "netAmount": 0.8, "organizationName": "GitHub", "repositoryName": "github/example" } ] }
{% rowheaders %}
| Previous property | Calculate from new API response |
|---|---|
days_left_in_billing_cycle |
Not available. This information can be inferred by subtracting the current day of the month from the number of days in the current month. |
estimated_paid_storage_for_month |
This is now represented as a $ amount via netAmount. Prerequisite: pass the month and year query parameters. For Actions storage
|
estimated_storage_for_month |
Prerequisite: pass the month and year query parameters. For Actions storage
|
{% endrowheaders %}