Endpoints da API REST para conformidade com licenças
Use a API REST para verificar os pacotes em relação à política de conformidade de licença de um repositório.
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.
Tokens de acesso granulares para "Get the license compliance policy for an enterprise"
Este endpoint funciona com os seguintes tipos de token granulares:
O token refinado deve ter os seguintes conjuntos de permissões:
- "Enterprise license policy" enterprise permissions (read)
Parâmetros para "Get the license compliance policy for an enterprise"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
enterprise string ObrigatórioThe slug version of the enterprise name. |
policy_id string ObrigatórioThe unique identifier of the policy within the enterprise. Currently, only |
Códigos de status de resposta HTTP para "Get the license compliance policy for an enterprise"
| Código de status | Descrição |
|---|---|
200 | OK |
404 | Resource not found |
503 | Service unavailable |
Exemplos de código para "Get the license compliance policy for an enterprise"
Se você acessar GitHub em GHE.com, substitua api.github.com pelo subdomínio dedicado da sua empresa em api.SUBDOMAIN.ghe.com.
Exemplo de solicitação
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.
Tokens de acesso granulares para "Set the license compliance policy for an enterprise"
Este endpoint funciona com os seguintes tipos de token granulares:
O token refinado deve ter os seguintes conjuntos de permissões:
- "Enterprise license policy" enterprise permissions (write)
Parâmetros para "Set the license compliance policy for an enterprise"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
enterprise string ObrigatórioThe slug version of the enterprise name. |
policy_id string ObrigatórioThe unique identifier of the policy within the enterprise. Currently, only |
| Nome, Tipo, Descrição | |||||||
|---|---|---|---|---|---|---|---|
licenses object Obrigatório | |||||||
Properties of |
| Nome, Tipo, Descrição | |||
|---|---|---|---|
allowed array of objects ObrigatórioThe licenses allowed by this policy. | |||
Properties of |
| Nome, Tipo, Descrição |
|---|
spdx_id string ObrigatórioThe SPDX identifier of the license. |
added_at string or null ObrigatórioThe time the license was added to the policy. |
packages array of objects ObrigatórioThe package-level exceptions in this policy.
Properties of packages
| Nome, Tipo, Descrição |
|---|
package_manager string ObrigatórioThe package manager the package belongs to. Pode ser um dos: |
name string ObrigatórioThe name of the package. |
action string ObrigatórioHow the package is treated by the policy. Pode ser um dos: |
reason string ObrigatórioThe reason the exception was added. |
extra_allowed_spdx_ids array of strings ObrigatórioAdditional SPDX identifiers allowed for this package. |
added_at string or null ObrigatórioThe time the exception was added to the policy. |
Códigos de status de resposta HTTP para "Set the license compliance policy for an enterprise"
| Código de status | Descrição |
|---|---|
204 | A header with no content is returned. |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
503 | Service unavailable |
Exemplos de código para "Set the license compliance policy for an enterprise"
Se você acessar GitHub em GHE.com, substitua api.github.com pelo subdomínio dedicado da sua empresa em api.SUBDOMAIN.ghe.com.
Exemplo de solicitação
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.
Tokens de acesso granulares para "Check license compliance for packages"
Este endpoint funciona com os seguintes tipos de token granulares:
- tokens de acesso do usuário do aplicativo GitHub
- tokens de acesso à instalação do aplicativo GitHub
- Tokens de acesso pessoal refinados
O token refinado deve ter os seguintes conjuntos de permissões:
- "Repository license policy" repository permissions (read)
Parâmetros para "Check license compliance for packages"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
owner string ObrigatórioThe account owner of the repository. The name is not case sensitive. |
repo string ObrigatórioThe name of the repository without the |
| Nome, Tipo, Descrição |
|---|
purls array of strings ObrigatórioUp to 40 package URLs to check against the license compliance policy. Duplicate package URLs count toward the limit but are checked once. |
Códigos de status de resposta HTTP para "Check license compliance for packages"
| Código de status | Descrição |
|---|---|
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 |
Exemplos de código para "Check license compliance for packages"
Se você acessar GitHub em GHE.com, substitua api.github.com pelo subdomínio dedicado da sua empresa em api.SUBDOMAIN.ghe.com.
Exemplos de solicitação
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"
}
}
}