# Issue links API

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

*   [List issue relations](#list-issue-relations)
*   [Create an issue link](#create-an-issue-link)
*   [Delete an issue link](#delete-an-issue-link)

# Issue links API[](#issue-links-api-starter "Permalink")

## List issue relations[](#list-issue-relations "Permalink")

获取给定问题的相关问题列表，按关系创建日期时间（升序）排序. 问题将根据用户授权进行过滤.

```
GET /projects/:id/issues/:issue_iid/links 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `issue_iid` | integer | yes | 项目问题的内部 ID |

```
[  {  "id"  :  84,  "iid"  :  14,  "issue_link_id":  1  "project_id"  :  4,  "created_at"  :  "2016-01-07T12:44:33.959Z",  "title"  :  "Issues with auth",  "state"  :  "opened",  "assignees"  :  [],  "assignee"  :  null,  "labels"  :  [  "bug"  ],  "author"  :  {  "name"  :  "Alexandra Bashirian",  "avatar_url"  :  null,  "state"  :  "active",  "web_url"  :  "https://gitlab.example.com/eileen.lowe",  "id"  :  18,  "username"  :  "eileen.lowe"  },  "description"  :  null,  "updated_at"  :  "2016-01-07T12:44:33.959Z",  "milestone"  :  null,  "subscribed"  :  true,  "user_notes_count":  0,  "due_date":  null,  "web_url":  "http://example.com/example/example/issues/14",  "confidential":  false,  "weight":  null,  "link_type":  "relates_to"  }  ] 
```

## Create an issue link[](#create-an-issue-link "Permalink")

在两个问题之间创建双向关系. 必须允许用户更新两个问题才能成功.

```
POST /projects/:id/issues/:issue_iid/links 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `issue_iid` | integer | yes | 项目问题的内部 ID |
| `target_project_id` | integer/string | yes | 目标项目[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `target_issue_iid` | integer/string | yes | 目标项目的内部 ID |
| `link_type` | string | no | 关系的类型（" relates_to"，" blocks"，" is_blocked_by"）默认为" relates_to". |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/4/issues/1/links?target_project_id=5&target_issue_iid=1" 
```

响应示例：

```
{  "source_issue"  :  {  "id"  :  83,  "iid"  :  11,  "project_id"  :  4,  "created_at"  :  "2016-01-07T12:44:33.959Z",  "title"  :  "Issues with auth",  "state"  :  "opened",  "assignees"  :  [],  "assignee"  :  null,  "labels"  :  [  "bug"  ],  "author"  :  {  "name"  :  "Alexandra Bashirian",  "avatar_url"  :  null,  "state"  :  "active",  "web_url"  :  "https://gitlab.example.com/eileen.lowe",  "id"  :  18,  "username"  :  "eileen.lowe"  },  "description"  :  null,  "updated_at"  :  "2016-01-07T12:44:33.959Z",  "milestone"  :  null,  "subscribed"  :  true,  "user_notes_count":  0,  "due_date":  null,  "web_url":  "http://example.com/example/example/issues/11",  "confidential":  false,  "weight":  null,  },  "target_issue"  :  {  "id"  :  84,  "iid"  :  14,  "project_id"  :  4,  "created_at"  :  "2016-01-07T12:44:33.959Z",  "title"  :  "Issues with auth",  "state"  :  "opened",  "assignees"  :  [],  "assignee"  :  null,  "labels"  :  [  "bug"  ],  "author"  :  {  "name"  :  "Alexandra Bashirian",  "avatar_url"  :  null,  "state"  :  "active",  "web_url"  :  "https://gitlab.example.com/eileen.lowe",  "id"  :  18,  "username"  :  "eileen.lowe"  },  "description"  :  null,  "updated_at"  :  "2016-01-07T12:44:33.959Z",  "milestone"  :  null,  "subscribed"  :  true,  "user_notes_count":  0,  "due_date":  null,  "web_url":  "http://example.com/example/example/issues/14",  "confidential":  false,  "weight":  null,  },  "link_type":  "relates_to"  } 
```

## Delete an issue link[](#delete-an-issue-link "Permalink")

删除问题链接，从而删除双向关系.

```
DELETE /projects/:id/issues/:issue_iid/links/:issue_link_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `issue_iid` | integer | yes | 项目问题的内部 ID |
| `issue_link_id` | integer/string | yes | 发行关系的 ID |
| `link_type` | string | no | 关系的类型（" relates_to"，" blocks"，" is_blocked_by"）默认为" relates_to" |

```
{  "source_issue"  :  {  "id"  :  83,  "iid"  :  11,  "project_id"  :  4,  "created_at"  :  "2016-01-07T12:44:33.959Z",  "title"  :  "Issues with auth",  "state"  :  "opened",  "assignees"  :  [],  "assignee"  :  null,  "labels"  :  [  "bug"  ],  "author"  :  {  "name"  :  "Alexandra Bashirian",  "avatar_url"  :  null,  "state"  :  "active",  "web_url"  :  "https://gitlab.example.com/eileen.lowe",  "id"  :  18,  "username"  :  "eileen.lowe"  },  "description"  :  null,  "updated_at"  :  "2016-01-07T12:44:33.959Z",  "milestone"  :  null,  "subscribed"  :  true,  "user_notes_count":  0,  "due_date":  null,  "web_url":  "http://example.com/example/example/issues/11",  "confidential":  false,  "weight":  null,  },  "target_issue"  :  {  "id"  :  84,  "iid"  :  14,  "project_id"  :  4,  "created_at"  :  "2016-01-07T12:44:33.959Z",  "title"  :  "Issues with auth",  "state"  :  "opened",  "assignees"  :  [],  "assignee"  :  null,  "labels"  :  [  "bug"  ],  "author"  :  {  "name"  :  "Alexandra Bashirian",  "avatar_url"  :  null,  "state"  :  "active",  "web_url"  :  "https://gitlab.example.com/eileen.lowe",  "id"  :  18,  "username"  :  "eileen.lowe"  },  "description"  :  null,  "updated_at"  :  "2016-01-07T12:44:33.959Z",  "milestone"  :  null,  "subscribed"  :  true,  "user_notes_count":  0,  "due_date":  null,  "web_url":  "http://example.com/example/example/issues/14",  "confidential":  false,  "weight":  null,  },  "link_type":  "relates_to"  } 
```