# gists 的 REST API 终结点

使用 REST API 列出、创建、更新和删除 GitHub 上的公共 Gist。

## 关于 gists

可使用 REST API 查看和修改 Gist。 有关 Gist 的详细信息，请参阅“[编辑内容以及与 gist 共享内容](/zh/enterprise-server@3.19/get-started/writing-on-github/editing-and-sharing-content-with-gists)”。

### 身份验证

可以匿名读取公共 Gist  并为没有令牌的匿名用户创建它们。要代表用户读取或写入 Gist，需要 Gist OAuth 范围和令牌。 有关详细信息，请参阅“[OAuth 应用的范围](/zh/enterprise-server@3.19/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps)”。

<!-- When an OAuth client does not have the gists scope, the API will return a 404 "Not Found" response regardless of the validity of the credentials. The API will return a 401 "Bad credentials" response if the gists scope was given to the application but the credentials are invalid. -->

### 截断

该 API 为 Gist 中的每个文件提供最多一兆字节的内容。 通过 API 为 Gist 返回的每个文件都有一个名为 `truncated` 的密钥。 如果 `truncated` 是 `true`，则文件太大，仅返回了 `content` 部分内容。

如果需要文件的完整内容，可以向 `GET` 指定的 URL 发出 `raw_url` 请求。 请注意，对于超过十兆字节的文件，需要通过 `git_pull_url` 提供的 URL 克隆 Gist。

除了特定文件的内容被截断外，如果文件总数超过 300 个，则整个文件列表也可能被截断。 如果顶层 `truncated` 键为 `true`，则仅返回文件列表中的前 300 个文件。 如果需要获取 Gist 的所有文件，需要通过 `git_pull_url` 提供的 URL 克隆 Gist。

> \[!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.

## List gists for the authenticated user

```
GET /gists
```

Lists the authenticated user's gists or if called anonymously, this endpoint returns all public gists:

### Parameters

#### Headers

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

#### Path and query parameters

* **`since`** (string)
  Only show results that were last updated after the given time. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

* **`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

* **403** - Forbidden

### Code examples

#### Example

**Request:**

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

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

Array of `Base Gist`:

* `url`: required, string, format: uri
* `forks_url`: required, string, format: uri
* `commits_url`: required, string, format: uri
* `id`: required, string
* `node_id`: required, string
* `git_pull_url`: required, string, format: uri
* `git_push_url`: required, string, format: uri
* `html_url`: required, string, format: uri
* `files`: required, object, additional properties: object
* `public`: required, boolean
* `created_at`: required, string, format: date-time
* `updated_at`: required, string, format: date-time
* `description`: required, string or null
* `comments`: required, integer
* `comments_enabled`: boolean
* `user`: required, any of:
  * **null**
  * **Simple User**
    * `name`: string or null
    * `email`: string or null
    * `login`: required, string
    * `id`: required, integer, format: int64
    * `node_id`: required, string
    * `avatar_url`: required, string, format: uri
    * `gravatar_id`: required, string or null
    * `url`: required, string, format: uri
    * `html_url`: required, string, format: uri
    * `followers_url`: required, string, format: uri
    * `following_url`: required, string
    * `gists_url`: required, string
    * `starred_url`: required, string
    * `subscriptions_url`: required, string, format: uri
    * `organizations_url`: required, string, format: uri
    * `repos_url`: required, string, format: uri
    * `events_url`: required, string
    * `received_events_url`: required, string, format: uri
    * `type`: required, string
    * `site_admin`: required, boolean
    * `starred_at`: string
    * `user_view_type`: string
* `comments_url`: required, string, format: uri
* `owner`: `Simple User`:
  * `name`: string or null
  * `email`: string or null
  * `login`: required, string
  * `id`: required, integer, format: int64
  * `node_id`: required, string
  * `avatar_url`: required, string, format: uri
  * `gravatar_id`: required, string or null
  * `url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `followers_url`: required, string, format: uri
  * `following_url`: required, string
  * `gists_url`: required, string
  * `starred_url`: required, string
  * `subscriptions_url`: required, string, format: uri
  * `organizations_url`: required, string, format: uri
  * `repos_url`: required, string, format: uri
  * `events_url`: required, string
  * `received_events_url`: required, string, format: uri
  * `type`: required, string
  * `site_admin`: required, boolean
  * `starred_at`: string
  * `user_view_type`: string
* `truncated`: boolean
* `forks`: array of object
* `history`: array of object

## Create a gist

```
POST /gists
```

Allows you to add a new gist with one or more files.
Note

Don't name your files "gistfile" with a numerical suffix. This is the format of the automatic naming scheme that Gist uses internally.

### Parameters

#### Headers

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

#### Body parameters

* **`description`** (string)
  Description of the gist

* **`files`** (object) (required)
  Names and content for the files that make up the gist
  * **`key`** (object)
    A user-defined key to represent an item in files.
    * **`content`** (string) (required)
      Content of the file

* **`public`** (boolean or string)
  Flag indicating whether the gist is public

### HTTP response status codes

* **201** - Created

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Creating a gist

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/gists \
  -d '{
  "description": "Example of a gist",
  "public": false,
  "files": {
    "README.md": {
      "content": "Hello World"
    }
  }
}'
```

**Response schema (Status: 201):**

* `forks`: array of objects or null:
  * `id`: string
  * `url`: string, format: uri
  * `user`: `Public User`:
    * `login`: required, string
    * `id`: required, integer, format: int64
    * `user_view_type`: string
    * `node_id`: required, string
    * `avatar_url`: required, string, format: uri
    * `gravatar_id`: required, string or null
    * `url`: required, string, format: uri
    * `html_url`: required, string, format: uri
    * `followers_url`: required, string, format: uri
    * `following_url`: required, string
    * `gists_url`: required, string
    * `starred_url`: required, string
    * `subscriptions_url`: required, string, format: uri
    * `organizations_url`: required, string, format: uri
    * `repos_url`: required, string, format: uri
    * `events_url`: required, string
    * `received_events_url`: required, string, format: uri
    * `type`: required, string
    * `site_admin`: required, boolean
    * `name`: required, string or null
    * `company`: required, string or null
    * `blog`: required, string or null
    * `location`: required, string or null
    * `email`: required, string or null, format: email
    * `notification_email`: string or null, format: email
    * `hireable`: required, boolean or null
    * `bio`: required, string or null
    * `twitter_username`: string or null
    * `public_repos`: required, integer
    * `public_gists`: required, integer
    * `followers`: required, integer
    * `following`: required, integer
    * `created_at`: required, string, format: date-time
    * `updated_at`: required, string, format: date-time
    * `plan`: object:
      * `collaborators`: required, integer
      * `name`: required, string
      * `space`: required, integer
      * `private_repos`: required, integer
    * `private_gists`: integer
    * `total_private_repos`: integer
    * `owned_private_repos`: integer
    * `disk_usage`: integer
    * `collaborators`: integer
  * `created_at`: string, format: date-time
  * `updated_at`: string, format: date-time
* `history`: array of `Gist History` or null:
  * `user`: any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `version`: string
  * `committed_at`: string, format: date-time
  * `change_status`: object:
    * `total`: integer
    * `additions`: integer
    * `deletions`: integer
  * `url`: string, format: uri
* `fork_of`: `Gist`:
  * `url`: required, string, format: uri
  * `forks_url`: required, string, format: uri
  * `commits_url`: required, string, format: uri
  * `id`: required, string
  * `node_id`: required, string
  * `git_pull_url`: required, string, format: uri
  * `git_push_url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `files`: required, object, additional properties: object
  * `public`: required, boolean
  * `created_at`: required, string, format: date-time
  * `updated_at`: required, string, format: date-time
  * `description`: required, string or null
  * `comments`: required, integer
  * `comments_enabled`: boolean
  * `user`: required, any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `comments_url`: required, string, format: uri
  * `owner`: any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `truncated`: boolean
  * `forks`: array of object
  * `history`: array of object
* `url`: string
* `forks_url`: string
* `commits_url`: string
* `id`: string
* `node_id`: string
* `git_pull_url`: string
* `git_push_url`: string
* `html_url`: string
* `files`: object, additional properties: object or null
* `public`: boolean
* `created_at`: string
* `updated_at`: string
* `description`: string or null
* `comments`: integer
* `comments_enabled`: boolean
* `user`: string or null
* `comments_url`: string
* `owner`: `Simple User`:
  * `name`: string or null
  * `email`: string or null
  * `login`: required, string
  * `id`: required, integer, format: int64
  * `node_id`: required, string
  * `avatar_url`: required, string, format: uri
  * `gravatar_id`: required, string or null
  * `url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `followers_url`: required, string, format: uri
  * `following_url`: required, string
  * `gists_url`: required, string
  * `starred_url`: required, string
  * `subscriptions_url`: required, string, format: uri
  * `organizations_url`: required, string, format: uri
  * `repos_url`: required, string, format: uri
  * `events_url`: required, string
  * `received_events_url`: required, string, format: uri
  * `type`: required, string
  * `site_admin`: required, boolean
  * `starred_at`: string
  * `user_view_type`: string
* `truncated`: boolean

## List public gists

```
GET /gists/public
```

List public gists sorted by most recently updated to least recently updated.
Note: With pagination, you can fetch up to 3000 gists. For example, you can fetch 100 pages with 30 gists per page or 30 pages with 100 gists per page.

### Parameters

#### Headers

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

#### Path and query parameters

* **`since`** (string)
  Only show results that were last updated after the given time. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

* **`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

* **403** - Forbidden

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

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

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

Same response schema as [List gists for the authenticated user](#list-gists-for-the-authenticated-user).

## List starred gists

```
GET /gists/starred
```

List the authenticated user's starred gists:

### Parameters

#### Headers

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

#### Path and query parameters

* **`since`** (string)
  Only show results that were last updated after the given time. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

* **`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

* **401** - Requires authentication

* **403** - Forbidden

### Code examples

#### Example

**Request:**

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

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

Same response schema as [List gists for the authenticated user](#list-gists-for-the-authenticated-user).

## Get a gist

```
GET /gists/{gist_id}
```

Gets a specified gist.
This endpoint supports the following custom media types. For more information, see "Media types."

application/vnd.github.raw+json: Returns the raw markdown. This is the default if you do not pass any specific media type.

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **403** - Forbidden Gist

* **404** - Resource not found

### Code examples

#### Example

**Request:**

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

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

Same response schema as [Create a gist](#create-a-gist).

## Update a gist

```
PATCH /gists/{gist_id}
```

Allows you to update a gist's description and to update, delete, or rename gist files. Files
from the previous version of the gist that aren't explicitly changed during an edit
are unchanged.
At least one of description or files is required.
This endpoint supports the following custom media types. For more information, see "Media types."

application/vnd.github.raw+json: Returns the raw markdown. This is the default if you do not pass any specific media type.

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

#### Body parameters

* **`description`** (string)
  The description of the gist.

* **`files`** (object)
  The gist files to be updated, renamed, or deleted. Each key must match the current filename
  (including extension) of the targeted gist file. For example: hello.py.
  To delete a file, set the whole file to null. For example: hello.py : null. The file will also be
  deleted if the specified object does not contain at least one of content or filename.
  * **`key`** (object)
    A user-defined key to represent an item in files.
    * **`content`** (string)
      The new content of the file.
    * **`filename`** (string or null)
      The new filename for the file.

### HTTP response status codes

* **200** - OK

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Updating a gist

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID \
  -d '{
  "description": "An updated gist description",
  "files": {
    "README.md": {
      "content": "Hello World from GitHub"
    }
  }
}'
```

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

Same response schema as [Create a gist](#create-a-gist).

#### Deleting a gist file

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID \
  -d '{
  "files": {
    "hello.py": null
  }
}'
```

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

Same response schema as [Create a gist](#create-a-gist).

#### Renaming a gist file

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID \
  -d '{
  "files": {
    "hello.py": {
      "filename": "goodbye.py"
    }
  }
}'
```

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

Same response schema as [Create a gist](#create-a-gist).

## Delete a gist

```
DELETE /gists/{gist_id}
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **204** - No Content

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID
```

**Response schema (Status: 204):**

## List gist commits

```
GET /gists/{gist_id}/commits
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

* **`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

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

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

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

Array of `Gist Commit`:

* `url`: required, string, format: uri
* `version`: required, string
* `user`: required, any of:
  * **null**
  * **Simple User**
    * `name`: string or null
    * `email`: string or null
    * `login`: required, string
    * `id`: required, integer, format: int64
    * `node_id`: required, string
    * `avatar_url`: required, string, format: uri
    * `gravatar_id`: required, string or null
    * `url`: required, string, format: uri
    * `html_url`: required, string, format: uri
    * `followers_url`: required, string, format: uri
    * `following_url`: required, string
    * `gists_url`: required, string
    * `starred_url`: required, string
    * `subscriptions_url`: required, string, format: uri
    * `organizations_url`: required, string, format: uri
    * `repos_url`: required, string, format: uri
    * `events_url`: required, string
    * `received_events_url`: required, string, format: uri
    * `type`: required, string
    * `site_admin`: required, boolean
    * `starred_at`: string
    * `user_view_type`: string
* `change_status`: required, object:
  * `total`: integer
  * `additions`: integer
  * `deletions`: integer
* `committed_at`: required, string, format: date-time

## List gist forks

```
GET /gists/{gist_id}/forks
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

* **`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

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

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

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

Array of `Gist Simple`:

* `forks`: array of objects or null:
  * `id`: string
  * `url`: string, format: uri
  * `user`: `Public User`:
    * `login`: required, string
    * `id`: required, integer, format: int64
    * `user_view_type`: string
    * `node_id`: required, string
    * `avatar_url`: required, string, format: uri
    * `gravatar_id`: required, string or null
    * `url`: required, string, format: uri
    * `html_url`: required, string, format: uri
    * `followers_url`: required, string, format: uri
    * `following_url`: required, string
    * `gists_url`: required, string
    * `starred_url`: required, string
    * `subscriptions_url`: required, string, format: uri
    * `organizations_url`: required, string, format: uri
    * `repos_url`: required, string, format: uri
    * `events_url`: required, string
    * `received_events_url`: required, string, format: uri
    * `type`: required, string
    * `site_admin`: required, boolean
    * `name`: required, string or null
    * `company`: required, string or null
    * `blog`: required, string or null
    * `location`: required, string or null
    * `email`: required, string or null, format: email
    * `notification_email`: string or null, format: email
    * `hireable`: required, boolean or null
    * `bio`: required, string or null
    * `twitter_username`: string or null
    * `public_repos`: required, integer
    * `public_gists`: required, integer
    * `followers`: required, integer
    * `following`: required, integer
    * `created_at`: required, string, format: date-time
    * `updated_at`: required, string, format: date-time
    * `plan`: object:
      * `collaborators`: required, integer
      * `name`: required, string
      * `space`: required, integer
      * `private_repos`: required, integer
    * `private_gists`: integer
    * `total_private_repos`: integer
    * `owned_private_repos`: integer
    * `disk_usage`: integer
    * `collaborators`: integer
  * `created_at`: string, format: date-time
  * `updated_at`: string, format: date-time
* `history`: array of `Gist History` or null:
  * `user`: any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `version`: string
  * `committed_at`: string, format: date-time
  * `change_status`: object:
    * `total`: integer
    * `additions`: integer
    * `deletions`: integer
  * `url`: string, format: uri
* `fork_of`: `Gist`:
  * `url`: required, string, format: uri
  * `forks_url`: required, string, format: uri
  * `commits_url`: required, string, format: uri
  * `id`: required, string
  * `node_id`: required, string
  * `git_pull_url`: required, string, format: uri
  * `git_push_url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `files`: required, object, additional properties: object
  * `public`: required, boolean
  * `created_at`: required, string, format: date-time
  * `updated_at`: required, string, format: date-time
  * `description`: required, string or null
  * `comments`: required, integer
  * `comments_enabled`: boolean
  * `user`: required, any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `comments_url`: required, string, format: uri
  * `owner`: any of:
    * **null**
    * **Simple User**
      * `name`: string or null
      * `email`: string or null
      * `login`: required, string
      * `id`: required, integer, format: int64
      * `node_id`: required, string
      * `avatar_url`: required, string, format: uri
      * `gravatar_id`: required, string or null
      * `url`: required, string, format: uri
      * `html_url`: required, string, format: uri
      * `followers_url`: required, string, format: uri
      * `following_url`: required, string
      * `gists_url`: required, string
      * `starred_url`: required, string
      * `subscriptions_url`: required, string, format: uri
      * `organizations_url`: required, string, format: uri
      * `repos_url`: required, string, format: uri
      * `events_url`: required, string
      * `received_events_url`: required, string, format: uri
      * `type`: required, string
      * `site_admin`: required, boolean
      * `starred_at`: string
      * `user_view_type`: string
  * `truncated`: boolean
  * `forks`: array of object
  * `history`: array of object
* `url`: string
* `forks_url`: string
* `commits_url`: string
* `id`: string
* `node_id`: string
* `git_pull_url`: string
* `git_push_url`: string
* `html_url`: string
* `files`: object, additional properties: object or null
* `public`: boolean
* `created_at`: string
* `updated_at`: string
* `description`: string or null
* `comments`: integer
* `comments_enabled`: boolean
* `user`: string or null
* `comments_url`: string
* `owner`: `Simple User`:
  * `name`: string or null
  * `email`: string or null
  * `login`: required, string
  * `id`: required, integer, format: int64
  * `node_id`: required, string
  * `avatar_url`: required, string, format: uri
  * `gravatar_id`: required, string or null
  * `url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `followers_url`: required, string, format: uri
  * `following_url`: required, string
  * `gists_url`: required, string
  * `starred_url`: required, string
  * `subscriptions_url`: required, string, format: uri
  * `organizations_url`: required, string, format: uri
  * `repos_url`: required, string, format: uri
  * `events_url`: required, string
  * `received_events_url`: required, string, format: uri
  * `type`: required, string
  * `site_admin`: required, boolean
  * `starred_at`: string
  * `user_view_type`: string
* `truncated`: boolean

## Fork a gist

```
POST /gists/{gist_id}/forks
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **201** - Created

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID/forks
```

**Response schema (Status: 201):**

* `url`: required, string, format: uri
* `forks_url`: required, string, format: uri
* `commits_url`: required, string, format: uri
* `id`: required, string
* `node_id`: required, string
* `git_pull_url`: required, string, format: uri
* `git_push_url`: required, string, format: uri
* `html_url`: required, string, format: uri
* `files`: required, object, additional properties: object
* `public`: required, boolean
* `created_at`: required, string, format: date-time
* `updated_at`: required, string, format: date-time
* `description`: required, string or null
* `comments`: required, integer
* `comments_enabled`: boolean
* `user`: required, any of:
  * **null**
  * **Simple User**
    * `name`: string or null
    * `email`: string or null
    * `login`: required, string
    * `id`: required, integer, format: int64
    * `node_id`: required, string
    * `avatar_url`: required, string, format: uri
    * `gravatar_id`: required, string or null
    * `url`: required, string, format: uri
    * `html_url`: required, string, format: uri
    * `followers_url`: required, string, format: uri
    * `following_url`: required, string
    * `gists_url`: required, string
    * `starred_url`: required, string
    * `subscriptions_url`: required, string, format: uri
    * `organizations_url`: required, string, format: uri
    * `repos_url`: required, string, format: uri
    * `events_url`: required, string
    * `received_events_url`: required, string, format: uri
    * `type`: required, string
    * `site_admin`: required, boolean
    * `starred_at`: string
    * `user_view_type`: string
* `comments_url`: required, string, format: uri
* `owner`: `Simple User`:
  * `name`: string or null
  * `email`: string or null
  * `login`: required, string
  * `id`: required, integer, format: int64
  * `node_id`: required, string
  * `avatar_url`: required, string, format: uri
  * `gravatar_id`: required, string or null
  * `url`: required, string, format: uri
  * `html_url`: required, string, format: uri
  * `followers_url`: required, string, format: uri
  * `following_url`: required, string
  * `gists_url`: required, string
  * `starred_url`: required, string
  * `subscriptions_url`: required, string, format: uri
  * `organizations_url`: required, string, format: uri
  * `repos_url`: required, string, format: uri
  * `events_url`: required, string
  * `received_events_url`: required, string, format: uri
  * `type`: required, string
  * `site_admin`: required, boolean
  * `starred_at`: string
  * `user_view_type`: string
* `truncated`: boolean
* `forks`: array of object
* `history`: array of object

## Check if a gist is starred

```
GET /gists/{gist_id}/star
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **204** - Response if gist is starred

* **304** - Not modified

* **403** - Forbidden

* **404** - Not Found if gist is not starred

### Code examples

#### Example

**Request:**

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

**Response schema (Status: 204):**

## Star a gist

```
PUT /gists/{gist_id}/star
```

Note that you'll need to set Content-Length to zero when calling out to this endpoint. For more information, see "HTTP method."

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **204** - No Content

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X PUT \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID/star
```

**Response schema (Status: 204):**

## Unstar a gist

```
DELETE /gists/{gist_id}/star
```

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

### HTTP response status codes

* **204** - No Content

* **304** - Not modified

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/gists/GIST_ID/star
```

**Response schema (Status: 204):**

## Get a gist revision

```
GET /gists/{gist_id}/{sha}
```

Gets a specified gist revision.
This endpoint supports the following custom media types. For more information, see "Media types."

application/vnd.github.raw+json: Returns the raw markdown. This is the default if you do not pass any specific media type.

### Parameters

#### Headers

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

#### Path and query parameters

* **`gist_id`** (string) (required)
  The unique identifier of the gist.

* **`sha`** (string) (required)

### HTTP response status codes

* **200** - OK

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

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

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

Same response schema as [Create a gist](#create-a-gist).

## List gists for a user

```
GET /users/{username}/gists
```

Lists public gists for the specified user:

### Parameters

#### Headers

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

#### Path and query parameters

* **`username`** (string) (required)
  The handle for the GitHub user account.

* **`since`** (string)
  Only show results that were last updated after the given time. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

* **`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

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

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

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

Same response schema as [List gists for the authenticated user](#list-gists-for-the-authenticated-user).