REST-API-Endpunkte zur Lizenzkonformität
Verwenden Sie die REST-API, um Pakete anhand der Lizenzcompliance-Richtlinie eines Repositorys zu überprüfen.
Get the license compliance policy for an enterprise
Gets the license compliance policy for an enterprise.
Currently, only the policy with the ID default is supported.
The authenticated user must be an enterprise owner, or have the "View enterprise license policy" or "Edit enterprise license policy" fine-grained permission on the enterprise.
Feinkörnige Zugriffstoken für "Get the license compliance policy for an enterprise"
Dieser Endpunkt funktioniert mit den folgenden differenzierten Tokentypen.:
Das differenzierte Token muss über den folgenden Berechtigungssatz verfügen.:
- "Enterprise license policy" enterprise permissions (read)
Parameter für "Get the license compliance policy for an enterprise"
| Name, Typ, BESCHREIBUNG |
|---|
accept string Setting to |
| Name, Typ, BESCHREIBUNG |
|---|
enterprise string ErforderlichThe slug version of the enterprise name. |
policy_id string ErforderlichThe unique identifier of the policy within the enterprise. Currently, only |
HTTP-Antwortstatuscodes für "Get the license compliance policy for an enterprise"
| Statuscode | BESCHREIBUNG |
|---|---|
200 | OK |
404 | Resource not found |
503 | Service unavailable |
Codebeispiele für "Get the license compliance policy for an enterprise"
Wenn Sie bei GHE.com auf GitHub zugreifen, ersetzen Sie api.github.com durch die dedizierte Unterdomäne Ihres Unternehmens unter api.SUBDOMAIN.ghe.com.
Anforderungsbeispiel
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/license-compliance/policies/POLICY_IDResponse
Status: 200{
"created_at": "2026-09-22T12:00:00Z",
"licenses": {
"allowed": [
{
"spdx_id": "MIT",
"added_at": "2026-09-22T12:00:00Z"
}
]
},
"packages": [
{
"package_manager": "npm",
"name": "example-package",
"action": "allowed",
"reason": "Approved exception.",
"extra_allowed_spdx_ids": [
"MIT"
],
"added_at": "2026-09-22T12:00:00Z"
}
]
}Set the license compliance policy for an enterprise
Sets the license compliance policy for an enterprise.
Currently, only the policy with the ID default is supported.
The authenticated user must be an enterprise owner, or have the "Edit enterprise license policy" fine-grained permission on the enterprise.
Feinkörnige Zugriffstoken für "Set the license compliance policy for an enterprise"
Dieser Endpunkt funktioniert mit den folgenden differenzierten Tokentypen.:
Das differenzierte Token muss über den folgenden Berechtigungssatz verfügen.:
- "Enterprise license policy" enterprise permissions (write)
Parameter für "Set the license compliance policy for an enterprise"
| Name, Typ, BESCHREIBUNG |
|---|
accept string Setting to |
| Name, Typ, BESCHREIBUNG |
|---|
enterprise string ErforderlichThe slug version of the enterprise name. |
policy_id string ErforderlichThe unique identifier of the policy within the enterprise. Currently, only |
| Name, Typ, BESCHREIBUNG | |||||||
|---|---|---|---|---|---|---|---|
licenses object Erforderlich | |||||||
Properties of |
| Name, Typ, BESCHREIBUNG | |||
|---|---|---|---|
allowed array of objects ErforderlichThe licenses allowed by this policy. | |||
Properties of |
| Name, Typ, BESCHREIBUNG |
|---|
spdx_id string ErforderlichThe SPDX identifier of the license. |
added_at string or null ErforderlichThe time the license was added to the policy. |
packages array of objects ErforderlichThe package-level exceptions in this policy.
Properties of packages
| Name, Typ, BESCHREIBUNG |
|---|
package_manager string ErforderlichThe package manager the package belongs to. Kann eine der folgenden sein: |
name string ErforderlichThe name of the package. |
action string ErforderlichHow the package is treated by the policy. Kann eine der folgenden sein: |
reason string ErforderlichThe reason the exception was added. |
extra_allowed_spdx_ids array of strings ErforderlichAdditional SPDX identifiers allowed for this package. |
added_at string or null ErforderlichThe time the exception was added to the policy. |
HTTP-Antwortstatuscodes für "Set the license compliance policy for an enterprise"
| Statuscode | BESCHREIBUNG |
|---|---|
204 | A header with no content is returned. |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
503 | Service unavailable |
Codebeispiele für "Set the license compliance policy for an enterprise"
Wenn Sie bei GHE.com auf GitHub zugreifen, ersetzen Sie api.github.com durch die dedizierte Unterdomäne Ihres Unternehmens unter api.SUBDOMAIN.ghe.com.
Anforderungsbeispiel
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/license-compliance/policies/POLICY_ID \
-d '{"licenses":{"allowed":[{"spdx_id":"MIT","added_at":"2026-09-22T12:00:00Z"}]},"packages":[{"package_manager":"npm","name":"example-package","action":"allowed","reason":"Approved exception.","extra_allowed_spdx_ids":["MIT"],"added_at":"2026-09-22T12:00:00Z"}]}'A header with no content is returned.
Status: 204Check license compliance for packages
Checks whether packages identified by the supplied package URLs (PURLs) are allowed by the repository's license compliance policy.
For requests made on behalf of a user, that user must have write access to the repository or the "View repository license policy" permission.
OAuth apps and classic personal access tokens require the repo scope.
Feinkörnige Zugriffstoken für "Check license compliance for packages"
Dieser Endpunkt funktioniert mit den folgenden differenzierten Tokentypen.:
- GitHub App-Benutzerzugriffstoken
- GitHub-App-Installations-Zugriffstoken
- Feingranulare persönliche Zugriffstoken
Das differenzierte Token muss über den folgenden Berechtigungssatz verfügen.:
- "Repository license policy" repository permissions (read)
Parameter für "Check license compliance for packages"
| Name, Typ, BESCHREIBUNG |
|---|
accept string Setting to |
| Name, Typ, BESCHREIBUNG |
|---|
owner string ErforderlichThe account owner of the repository. The name is not case sensitive. |
repo string ErforderlichThe name of the repository without the |
| Name, Typ, BESCHREIBUNG |
|---|
purls array of strings ErforderlichUp to 40 package URLs to check against the license compliance policy. Duplicate package URLs count toward the limit but are checked once. |
HTTP-Antwortstatuscodes für "Check license compliance for packages"
| Statuscode | BESCHREIBUNG |
|---|---|
200 | Package license compliance results. |
403 | Forbidden |
404 | License compliance policy not found. |
422 | Validation failed, or the endpoint has been spammed. |
503 | Service unavailable |
Codebeispiele für "Check license compliance for packages"
Wenn Sie bei GHE.com auf GitHub zugreifen, ersetzen Sie api.github.com durch die dedizierte Unterdomäne Ihres Unternehmens unter api.SUBDOMAIN.ghe.com.
Beispiele für Anfragen
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/repos/OWNER/REPO/license-compliance/package-checks \
-d '{"purls":["pkg:npm/lodash@4.17.21"]}'Package license compliance results.
Status: 200{
"purls": {
"pkg:npm/lodash@4.17.21": {
"status": "allowed",
"license": "MIT",
"reason": "allowed_license"
}
}
}