# REST API 许可证端点

使用 REST API 检索常用开源许可证以及特定项目许可证文件的信息。

## 关于许可证

GitHub 使用 [开源 Ruby Gem 许可接收方](https://github.com/benbalter/licensee)来尝试标识项目的许可证。 许可接收方将项目的 `LICENSE` 文件（如果有）的内容与已知许可的简短列表相匹配。 因此，API 不考虑项目依赖项的许可或其他记录项目许可的方式，例如对文档中许可名称的引用。

如果许可匹配，则返回的许可密钥和名称符合 [SPDX 规范](https://spdx.org/)。

注意：这些终结点还将返回存储库的许可信息：

* [获取存储库](/zh/enterprise-server@3.20/rest/repos/repos#get-a-repository)
* [列出用户的存储库](/zh/enterprise-server@3.20/rest/repos/repos#list-repositories-for-a-user)
* [列出组织存储库](/zh/enterprise-server@3.20/rest/repos/repos#list-organization-repositories)
* [列出分支](/zh/enterprise-server@3.20/rest/repos/forks#list-forks)
* [列出用户关注的存储库](/zh/enterprise-server@3.20/rest/activity/watching#list-repositories-watched-by-a-user)
* [列出团队存储库](/zh/enterprise-server@3.20/rest/teams/teams#list-team-repositories)

> \[!WARNING]
> GitHub是很多事情，但它不是一家律师事务所。 因此，GitHub 不提供法律建议。 使用 API 或向我们发送电子邮件并不构成法律意见，也不形成律师-客户关系。 如果您对特定许可可以做什么和不能做什么有任何疑问，您应该在继续之前先咨询自己的法律顾问。 事实上，在做出任何可能具有法律后果或影响您合法权利的决定之前，您都应该咨询自己的律师。
>
> GitHub 创建了这些终结点，旨在帮助用户获取有关开源许可证以及使用它们的项目的信息。 我们希望它有帮助，但请记住，我们不是律师（至少大多数人不是），像其他人一样，我们也会犯错。 因此，GitHub“按原样”提供 API，对提供或通过其提供的任何信息或许可证不做任何保证，并对使用 API 所造成的损害不承担责任。

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.

## Get all commonly used licenses

```
GET /licenses
```

Lists the most commonly used licenses on GitHub. For more information, see "Licensing a repository ."

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`featured`** (boolean)

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

### HTTP response status codes

* **200** - OK

* **304** - Not modified

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/licenses
```

**Response schema (Status: 200):**

Array of `License Simple`:

* `key`: required, string
* `name`: required, string
* `url`: required, string or null, format: uri
* `spdx_id`: required, string or null
* `node_id`: required, string
* `html_url`: string, format: uri

## Get a license

```
GET /licenses/{license}
```

Gets information about a specific license. For more information, see "Licensing a repository ."

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`license`** (string) (required)

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/licenses/LICENSE
```

**Response schema (Status: 200):**

* `key`: required, string
* `name`: required, string
* `spdx_id`: required, string or null
* `url`: required, string or null, format: uri
* `node_id`: required, string
* `html_url`: required, string, format: uri
* `description`: required, string
* `implementation`: required, string
* `permissions`: required, array of string
* `conditions`: required, array of string
* `limitations`: required, array of string
* `body`: required, string
* `featured`: required, boolean

## Get the license for a repository

```
GET /repos/{owner}/{repo}/license
```

This method returns the contents of the repository's license file, if one is detected.
This endpoint supports the following custom media types. For more information, see "Media types."

application/vnd.github.raw+json: Returns the raw contents of the license.
application/vnd.github.html+json: Returns the license contents in HTML. Markup languages are rendered to HTML using GitHub's open-source Markup library.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

* **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

* **`ref`** (string)
  The Git reference for the results you want to list. The ref for a branch can be formatted either as refs/heads/<branch name> or simply <branch name>. To reference a pull request use refs/pull/<number>/merge.

### HTTP response status codes

* **200** - OK

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/license
```

**Response schema (Status: 200):**

* `name`: required, string
* `path`: required, string
* `sha`: required, string
* `size`: required, integer
* `url`: required, string, format: uri
* `html_url`: required, string or null, format: uri
* `git_url`: required, string or null, format: uri
* `download_url`: required, string or null, format: uri
* `type`: required, string
* `content`: required, string
* `encoding`: required, string
* `_links`: required, object:
  * `git`: required, string or null, format: uri
  * `html`: required, string or null, format: uri
  * `self`: required, string, format: uri
* `license`: required, any of:
  * **null**
  * **License Simple**
    * `key`: required, string
    * `name`: required, string
    * `url`: required, string or null, format: uri
    * `spdx_id`: required, string or null
    * `node_id`: required, string
    * `html_url`: string, format: uri