成本中心
使用 REST API 获取成本中心信息。
Get all cost centers for an enterprise
Gets a list of all the cost centers for an enterprise.
“Get all cost centers for an enterprise”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Get all cost centers for an enterprise”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
| 名称, 类型, 说明 |
|---|
state string Set to 可以是以下选项之一: |
“Get all cost centers for an enterprise”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when getting cost centers |
400 | Bad Request |
403 | Forbidden |
500 | Internal Error |
503 | Service unavailable |
“Get all cost centers for an enterprise”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centersResponse when getting cost centers
Status: 200{
"costCenters": [
{
"id": "2eeb8ffe-6903-11ee-8c99-0242ac120002",
"name": "Cost Center Name",
"state": "active",
"azure_subscription": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"resources": [
{
"type": "User",
"name": "Monalisa"
},
{
"type": "Repo",
"name": "octocat/hello-world"
}
]
},
{
"id": "3ffb9ffe-6903-11ee-8c99-0242ac120003",
"name": "Another Cost Center",
"state": "active",
"resources": [
{
"type": "User",
"name": "Octocat"
}
]
}
]
}Create a new cost center
Creates a new cost center for an enterprise. The authenticated user must be an enterprise admin.
“Create a new cost center”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Create a new cost center”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
| 名称, 类型, 说明 |
|---|
name string 必须The name of the cost center (max length 255 characters) |
“Create a new cost center”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Cost center created successfully |
400 | Bad request |
409 | Conflict |
500 | Internal server error |
“Create a new cost center”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers \
-d '{"name":"Engineering Team"}'Example response for a created cost center
Status: 200{
"id": "abc123",
"name": "Engineering Team",
"resources": []
}Get a cost center by ID
Gets a cost center by ID. The authenticated user must be an enterprise admin.
“Get a cost center by ID”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Get a cost center by ID”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
cost_center_id string 必须The ID corresponding to the cost center. |
“Get a cost center by ID”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when getting a cost center |
400 | Bad Request |
403 | Forbidden |
500 | Internal Error |
503 | Service unavailable |
“Get a cost center by ID”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_IDResponse when getting a cost center
Status: 200{
"id": "2eeb8ffe-6903-11ee-8c99-0242ac120002",
"name": "Cost Center Name",
"state": "active",
"azure_subscription": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"resources": [
{
"type": "User",
"name": "Monalisa"
},
{
"type": "Repo",
"name": "octocat/hello-world"
}
]
}Update a cost center name
Updates an existing cost center name.
“Update a cost center name”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Update a cost center name”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name |
cost_center_id string 必须The unique identifier of the cost center |
| 名称, 类型, 说明 |
|---|
name string 必须The new name for the cost center |
“Update a cost center name”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when updating a cost center |
400 | Bad Request |
403 | Forbidden |
404 | Resource not found |
409 | Conflict |
500 | Internal Error |
503 | Service unavailable |
“Update a cost center name”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID \
-d '{"name":"New Cost Center Name"}'Response when updating a cost center
Status: 200{
"id": "2eeb8ffe-6903-11ee-8c99-0242ac120002",
"name": "Cost Center Name",
"state": "active",
"azure_subscription": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"resources": [
{
"type": "User",
"name": "Monalisa"
},
{
"type": "Repo",
"name": "octocat/hello-world"
}
]
}Delete a cost center
Archieves a cost center by ID. The authenticated user must be an enterprise admin.
“Delete a cost center”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Delete a cost center”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
cost_center_id string 必须The ID corresponding to the cost center. |
“Delete a cost center”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when deleting a cost center |
400 | Bad Request |
403 | Forbidden |
404 | Resource not found |
500 | Internal Error |
503 | Service unavailable |
“Delete a cost center”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_IDResponse when deleting a cost center
Status: 200{
"message": "Cost center successfully deleted.",
"id": "2066deda-923f-43f9-88d2-62395a28c0cdd",
"name": "cc3",
"costCenterState": "CostCenterArchived"
}Add resources to a cost center
Adds resources to a cost center.
The usage for the resources will be charged to the cost center's budget. The authenticated user must be an enterprise admin in order to use this endpoint.
“Add resources to a cost center”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Add resources to a cost center”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
cost_center_id string 必须The ID corresponding to the cost center. |
| 名称, 类型, 说明 |
|---|
users array of strings The usernames of the users to add to the cost center. |
organizations array of strings The organizations to add to the cost center. |
repositories array of strings The repositories to add to the cost center. |
“Add resources to a cost center”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when adding resources to a cost center |
400 | Bad Request |
403 | Forbidden |
409 | Conflict |
500 | Internal Error |
503 | Service unavailable |
“Add resources to a cost center”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \
-d '{"users":["monalisa"]}'Response when adding resources to a cost center
Status: 200{
"message": "Resources successfully added to the cost center.",
"reassigned_resources": [
{
"resource_type": "user",
"name": "monalisa",
"previous_cost_center": "old-cost-center"
},
{
"resource_type": "organization",
"name": "octo-org",
"previous_cost_center": "another-cost-center"
},
{
"resource_type": "repository",
"name": "octo-repo",
"previous_cost_center": "yet-another-cost-center"
}
]
}Remove resources from a cost center
Remove resources from a cost center.
The usage for the resources will no longer be charged to the cost center's budget. The authenticated user must be an enterprise admin in order to use this endpoint.
“Remove resources from a cost center”的细粒度访问令牌
此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。
“Remove resources from a cost center”的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
cost_center_id string 必须The ID corresponding to the cost center. |
| 名称, 类型, 说明 |
|---|
users array of strings The usernames of the users to remove from the cost center. |
organizations array of strings The organizations to remove from the cost center. |
repositories array of strings The repositories to remove from the cost center. |
“Remove resources from a cost center”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when removing resources from a cost center |
400 | Bad Request |
403 | Forbidden |
500 | Internal Error |
503 | Service unavailable |
“Remove resources from a cost center”的示例代码
如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \
-d '{"users":["monalisa"]}'Response when removing resources from a cost center
Status: 200{
"message": "Resources successfully removed from the cost center."
}