# Wikis API

> 原文：[https://docs.gitlab.com/ee/api/wikis.html](https://docs.gitlab.com/ee/api/wikis.html)

*   [List wiki pages](#list-wiki-pages)
*   [Get a wiki page](#get-a-wiki-page)
*   [Create a new wiki page](#create-a-new-wiki-page)
*   [Edit an existing wiki page](#edit-an-existing-wiki-page)
*   [Delete a wiki page](#delete-a-wiki-page)
*   [Upload an attachment to the wiki repository](#upload-an-attachment-to-the-wiki-repository)

# Wikis API[](#wikis-api "Permalink")

在 GitLab 10.0 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13372) .

仅在 APIv4 中可用.

## List wiki pages[](#list-wiki-pages "Permalink")

获取给定项目的所有 Wiki 页面.

```
GET /projects/:id/wikis 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `with_content` | boolean | no | 包含页面内容 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis?with_content=1" 
```

响应示例：

```
[  {  "content"  :  "Here is an instruction how to deploy this project.",  "format"  :  "markdown",  "slug"  :  "deploy",  "title"  :  "deploy"  },  {  "content"  :  "Our development process is described here.",  "format"  :  "markdown",  "slug"  :  "development",  "title"  :  "development"  },{  "content"  :  "*  [Deploy](deploy)\n*  [Development](development)",  "format"  :  "markdown",  "slug"  :  "home",  "title"  :  "home"  }  ] 
```

## Get a wiki page[](#get-a-wiki-page "Permalink")

获取给定项目的 Wiki 页面.

```
GET /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `slug` | string | yes | Wiki 页面的段（唯一字符串） |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/home" 
```

响应示例：

```
{  "content"  :  "home page",  "format"  :  "markdown",  "slug"  :  "home",  "title"  :  "home"  } 
```

## Create a new wiki page[](#create-a-new-wiki-page "Permalink")

使用给定的标题，条目和内容为给定的存储库创建一个新的 Wiki 页面.

```
POST /projects/:id/wikis 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `content` | string | yes | Wiki 页面的内容 |
| `title` | string | yes | 维基页面的标题 |
| `format` | string | no | Wiki 页面的格式. 可用格式为： `markdown` （默认）， `rdoc` ， `asciidoc`和`org` |

```
curl --data "format=rdoc&title=Hello&content=Hello world" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis" 
```

响应示例：

```
{  "content"  :  "Hello world",  "format"  :  "markdown",  "slug"  :  "Hello",  "title"  :  "Hello"  } 
```

## Edit an existing wiki page[](#edit-an-existing-wiki-page "Permalink")

更新现有的 Wiki 页面. 至少需要一个参数才能更新 Wiki 页面.

```
PUT /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `content` | string | 是，如果未提供`title` | Wiki 页面的内容 |
| `title` | string | 是，如果未提供`content` | 维基页面的标题 |
| `format` | string | no | Wiki 页面的格式. 可用格式为： `markdown` （默认）， `rdoc` ， `asciidoc`和`org` |
| `slug` | string | yes | Wiki 页面的段（唯一字符串） |

```
curl --request PUT --data "format=rdoc&content=documentation&title=Docs" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo" 
```

响应示例：

```
{  "content"  :  "documentation",  "format"  :  "markdown",  "slug"  :  "Docs",  "title"  :  "Docs"  } 
```

## Delete a wiki page[](#delete-a-wiki-page "Permalink")

删除带有给定子弹的 Wiki 页面.

```
DELETE /projects/:id/wikis/:slug 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `slug` | string | yes | Wiki 页面的段（唯一字符串） |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/wikis/foo" 
```

成功时，HTTP 状态代码为`204`并且不需要 JSON 响应.

## Upload an attachment to the wiki repository[](#upload-an-attachment-to-the-wiki-repository "Permalink")

将文件上传到 Wiki 信息库中的附件文件夹. 附件文件夹是`uploads`文件夹.

```
POST /projects/:id/wikis/attachments 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `file` | string | yes | 要上传的附件 |
| `branch` | string | no | 分支的名称. 默认为 Wiki 存储库默认分支 |

要从文件系统上载文件，请使用`--form`参数. 这将导致 cURL 使用标题`Content-Type: multipart/form-data` . `file=`参数必须指向文件系统上的文件，并以`@`开头. 例如：

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "file=@dk.png" "https://gitlab.example.com/api/v4/projects/1/wikis/attachments" 
```

响应示例：

```
{  "file_name"  :  "dk.png",  "file_path"  :  "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",  "branch"  :  "master",  "link"  :  {  "url"  :  "uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png",  "markdown"  :  "![dk](uploads/6a061c4cf9f1c28cb22c384b4b8d4e3c/dk.png)"  }  } 
```