パッケージ
REST API を使用して GitHub Packages を操作します。
GitHub Packages について
REST API を使用して GitHub リポジトリと組織のパッケージを管理できます。 詳しくは、「パッケージの復元と削除」をご覧ください。
REST API を使用して GitHub Packages を管理するには、personal access token (classic) を使用して認証する必要があります。
- パッケージのメタデータにアクセスするには、トークンに
read:packagesのスコープを含める必要があります。 - パッケージとパッケージのバージョンを削除するには、トークンに
read:packagesとdelete:packagesのスコープを含める必要があります。 - パッケージとパッケージのバージョンを復元するには、トークンに
read:packagesとwrite:packagesのスコープを含める必要があります。
細かなアクセス許可がサポートされているレジストリにパッケージが置かれている場合、トークンに repo 範囲がなくてもそのパッケージにアクセスしたり、管理したりできます。 リポジトリを範囲とするアクセス許可のみをサポートしているレジストリにパッケージが置かれている場合、トークンには repo 範囲も含まれている必要があります。パッケージは GitHub リポジトリからアクセス許可を継承するためです。 リポジトリを範囲とするアクセス許可のみをサポートするレジストリの一覧については、「GitHub Packages のアクセス許可について」を参照してください。
SSO が有効になっている組織のリソースにアクセスするには、personal access token (classic) の SSO を有効にする必要があります。 詳しい情報については、GitHub Enterprise Cloud ドキュメント内の「SAML シングル サインオンで使用するために personal access token を承認する」を参照してください
List packages for an organization
Lists all packages in an organization readable by the user.
To use this endpoint, you must authenticate using an access token with the read:packages scope. If the package_type belongs to a registry that only supports repository-scoped permissions, your token must also include the repo scope. For the list of GitHub Packages registries that only support repository-scoped permissions, see "About permissions for GitHub Packages."
パラメーター
| ヘッダー |
|---|
| 名前, Type, 説明 |
acceptstringSetting to |
| パス パラメーター |
| 名前, Type, 説明 |
orgstring必須The organization name. The name is not case sensitive. |
| クエリ パラメーター |
| 名前, Type, 説明 |
package_typestring必須The type of supported package. Packages in GitHub's Gradle registry have the type 次のいずれかにできます: |
visibilitystringThe selected visibility of the packages. This parameter is optional and only filters an existing result set. The 次のいずれかにできます: |
HTTP 応答状態コード
| 状態コード | 説明 |
|---|---|
200 | OK |
401 | Requires authentication |
403 | Forbidden |
コード サンプル
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/ORG/packages?package_type=containerResponse
Status: 200[
{
"id": 197,
"name": "hello_docker",
"package_type": "container",
"owner": {
"login": "github",
"id": 9919,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github",
"html_url": "https://github.com/github",
"followers_url": "https://api.github.com/users/github/followers",
"following_url": "https://api.github.com/users/github/following{/other_user}",
"gists_url": "https://api.github.com/users/github/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github/subscriptions",
"organizations_url": "https://api.github.com/users/github/orgs",
"repos_url": "https://api.github.com/users/github/repos",
"events_url": "https://api.github.com/users/github/events{/privacy}",
"received_events_url": "https://api.github.com/users/github/received_events",
"type": "Organization",
"site_admin": false
},
"version_count": 1,
"visibility": "private",
"url": "https://api.github.com/orgs/github/packages/container/hello_docker",
"created_at": "2020-05-19T22:19:11Z",
"updated_at": "2020-05-19T22:19:11Z",
"html_url": "https://github.com/orgs/github/packages/container/package/hello_docker"
},
{
"id": 198,
"name": "goodbye_docker",
"package_type": "container",
"owner": {
"login": "github",
"id": 9919,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github",
"html_url": "https://github.com/github",
"followers_url": "https://api.github.com/users/github/followers",
"following_url": "https://api.github.com/users/github/following{/other_user}",
"gists_url": "https://api.github.com/users/github/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github/subscriptions",
"organizations_url": "https://api.github.com/users/github/orgs",
"repos_url": "https://api.github.com/users/github/repos",
"events_url": "https://api.github.com/users/github/events{/privacy}",
"received_events_url": "https://api.github.com/users/github/received_events",
"type": "Organization",
"site_admin": false
},
"version_count": 2,
"visibility": "private",
"url": "https://api.github.com/orgs/github/packages/container/goodbye_docker",
"created_at": "2020-05-20T22:19:11Z",
"updated_at": "2020-05-20T22:19:11Z",
"html_url": "https://github.com/orgs/github/packages/container/package/goodbye_docker"
}
]Get a package for an organization
Gets a specific package in an organization.
To use this endpoint, you must authenticate using an access token with the read:packages scope. If the package_type belongs to a GitHub Packages registry that only supports repository-scoped permissions, your token must also include the repo scope. For the list of GitHub Packages registries that only support repository-scoped permissions, see "About permissions for GitHub Packages."
パラメーター
| ヘッダー |
|---|
| 名前, Type, 説明 |
acceptstringSetting to |
| パス パラメーター |
| 名前, Type, 説明 |
package_typestring必須The type of supported package. Packages in GitHub's Gradle registry have the type 次のいずれかにできます: |
package_namestring必須The name of the package. |
orgstring必須The organization name. The name is not case sensitive. |
HTTP 応答状態コード
| 状態コード | 説明 |
|---|---|
200 | OK |
コード サンプル
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/ORG/packages/PACKAGE_TYPE/PACKAGE_NAMEResponse
Status: 200{
"id": 197,
"name": "hello_docker",
"package_type": "container",
"owner": {
"login": "github",
"id": 9919,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github",
"html_url": "https://github.com/github",
"followers_url": "https://api.github.com/users/github/followers",
"following_url": "https://api.github.com/users/github/following{/other_user}",
"gists_url": "https://api.github.com/users/github/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github/subscriptions",
"organizations_url": "https://api.github.com/users/github/orgs",
"repos_url": "https://api.github.com/users/github/repos",
"events_url": "https://api.github.com/users/github/events{/privacy}",
"received_events_url": "https://api.github.com/users/github/received_events",
"type": "Organization",
"site_admin": false
},
"version_count": 1,
"visibility": "private",
"url": "https://api.github.com/orgs/github/packages/container/hello_docker",
"created_at": "2020-05-19T22:19:11Z",
"updated_at": "2020-05-19T22:19:11Z",
"html_url": "https://github.com/orgs/github/packages/container/package/hello_docker"
}Delete a package for an organization
Deletes an entire package in an organization. You cannot delete a public package if any version of the package has more than 5,000 downloads. In this scenario, contact GitHub support for further assistance.
To use this endpoint, you must have admin permissions in the organization and authenticate using an access token with the read:packages and delete:packages scopes. In addition:
- If the
package_typebelongs to a GitHub Packages registry that only supports repository-scoped permissions, your token must also include thereposcope. For the list of these registries, see "About permissions for GitHub Packages." - If the
package_typebelongs to a GitHub Packages registry that supports granular permissions, you must have admin permissions to the package you want to delete. For the list of these registries, see "About permissions for GitHub Packages."
パラメーター
| ヘッダー |
|---|
| 名前, Type, 説明 |
acceptstringSetting to |
| パス パラメーター |
| 名前, Type, 説明 |
package_typestring必須The type of supported package. Packages in GitHub's Gradle registry have the type 次のいずれかにできます: |
package_namestring必須The name of the package. |
orgstring必須The organization name. The name is not case sensitive. |
HTTP 応答状態コード
| 状態コード | 説明 |
|---|---|
204 | No Content |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
コード サンプル
curl \
-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/orgs/ORG/packages/PACKAGE_TYPE/PACKAGE_NAMEResponse
Status: 204Restore a package for an organization
Restores an entire package in an organization.
You can restore a deleted package under the following conditions:
- The package was deleted within the last 30 days.
- The same package namespace and version is still available and not reused for a new package. If the same package namespace is not available, you will not be able to restore your package. In this scenario, to restore the deleted package, you must delete the new package that uses the deleted package's namespace first.
To use this endpoint, you must have admin permissions in the organization and authenticate using an access token with the read:packages and write:packages scopes. In addition:
- If the
package_typebelongs to a GitHub Packages registry that only supports repository-scoped permissions, your token must also include thereposcope. For the list of these registries, see "About permissions for GitHub Packages." - If the
package_typebelongs to a GitHub Packages registry that supports granular permissions, you must have admin permissions to the package you want to restore. For the list of these registries, see "About permissions for GitHub Packages."
パラメーター
| ヘッダー |
|---|
| 名前, Type, 説明 |
acceptstringSetting to |
| パス パラメーター |
| 名前, Type, 説明 |
package_typestring必須The type of supported package. Packages in GitHub's Gradle registry have the type 次のいずれかにできます: |
package_namestring必須The name of the package. |
orgstring必須The organization name. The name is not case sensitive. |
| クエリ パラメーター |
| 名前, Type, 説明 |
tokenstringpackage token |
HTTP 応答状態コード
| 状態コード | 説明 |
|---|---|
204 | No Content |
401 | Requires authentication |
403 | Forbidden |
404 | Resource not found |
コード サンプル
curl \
-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/orgs/ORG/packages/PACKAGE_TYPE/PACKAGE_NAME/restoreResponse
Status: 204List package versions for a package owned by an organization
Lists package versions for a package owned by an organization.
If the package_type belongs to a GitHub Packages registry that only supports repository-scoped permissions, your token must also include the repo scope. For the list of GitHub Packages registries that only support repository-scoped permissions, see "About permissions for GitHub Packages."
パラメーター
| ヘッダー |
|---|
| 名前, Type, 説明 |
acceptstringSetting to |
| パス パラメーター |
| 名前, Type, 説明 |
package_typestring必須The type of supported package. Packages in GitHub's Gradle registry have the type 次のいずれかにできます: |
package_namestring必須The name of the package. |
orgstring必須The organization name. The name is not case sensitive. |
| クエリ パラメーター |
| 名前, Type, 説明 |
pageintegerPage number of the results to fetch. Default: |
per_pageintegerThe number of results per page (max 100). Default: |
statestringThe state of the package, either active or deleted. Default: 次のいずれかにできます: |