# Release links API

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

*   [Get links](#get-links)
*   [Get a link](#get-a-link)
*   [Create a link](#create-a-link)
*   [Update a link](#update-a-link)
*   [Delete a link](#delete-a-link)

# Release links API[](#release-links-api "Permalink")

在 GitLab 11.7 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41766) .

使用此 API，您可以操纵 GitLab 的[Release](../../user/project/releases/index.html)链接. 有关操纵其他 Release 资产的信息，请参见[Release API](index.html) . GitLab 支持指向`http` ， `https`和`ftp`资产的链接.

## Get links[](#get-links "Permalink")

从发布中获取资产作为链接.

```
GET /projects/:id/releases/:tag_name/assets/links 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](../README.html#namespaced-path-encoding) . |
| `tag_name` | string | yes | 与发行版关联的标签. |

请求示例：

```
curl --header "PRIVATE-TOKEN: n671WNGecHugsdEDPsyo" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links" 
```

响应示例：

```
[  {  "id":2,  "name":"awesome-v0.2.msi",  "url":"http://192.168.10.15:3000/msi",  "external":true,  "link_type":"other"  },  {  "id":1,  "name":"awesome-v0.2.dmg",  "url":"http://192.168.10.15:3000",  "external":true,  "link_type":"other"  }  ] 
```

## Get a link[](#get-a-link "Permalink")

从发布中获取资产作为链接.

```
GET /projects/:id/releases/:tag_name/assets/links/:link_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](../README.html#namespaced-path-encoding) . |
| `tag_name` | string | yes | 与发行版关联的标签. |
| `link_id` | integer | yes | 链接的 ID. |

请求示例：

```
curl --header "PRIVATE-TOKEN: n671WNGecHugsdEDPsyo" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1" 
```

响应示例：

```
{  "id":1,  "name":"awesome-v0.2.dmg",  "url":"http://192.168.10.15:3000",  "external":true,  "link_type":"other"  } 
```

## Create a link[](#create-a-link "Permalink")

从发布创建资产作为链接.

```
POST /projects/:id/releases/:tag_name/assets/links 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](../README.html#namespaced-path-encoding) . |
| `tag_name` | string | yes | 与发行版关联的标签. |
| `name` | string | yes | 链接的名称. |
| `url` | string | yes | 链接的 URL. |
| `link_type` | string | no | 链接的类型： `other` ， `runbook` ， `image` ， `package` . 默认为`other` . |

请求示例：

```
curl --request POST \
     --header "PRIVATE-TOKEN: n671WNGecHugsdEDPsyo" \
     --data name="awesome-v0.2.dmg" \
     --data url="http://192.168.10.15:3000" \
     "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links" 
```

响应示例：

```
{  "id":1,  "name":"awesome-v0.2.dmg",  "url":"http://192.168.10.15:3000",  "external":true,  "link_type":"other"  } 
```

## Update a link[](#update-a-link "Permalink")

将资产更新为发布中的链接.

```
PUT /projects/:id/releases/:tag_name/assets/links/:link_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](../README.html#namespaced-path-encoding) . |
| `tag_name` | string | yes | 与发行版关联的标签. |
| `link_id` | integer | yes | 链接的 ID. |
| `name` | string | no | 链接的名称. |
| `url` | string | no | 链接的 URL. |
| `link_type` | string | no | 链接的类型： `other` ， `runbook` ， `image` ， `package` . 默认为`other` . |

**注意**您必须至少指定`name`或`url`

请求示例：

```
curl --request PUT --data name="new name" --data link_type="runbook" --header "PRIVATE-TOKEN: n671WNGecHugsdEDPsyo" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1" 
```

响应示例：

```
{  "id":1,  "name":"new name",  "url":"http://192.168.10.15:3000",  "external":true,  "link_type":"runbook"  } 
```

## Delete a link[](#delete-a-link "Permalink")

从发布中删除资产作为链接.

```
DELETE /projects/:id/releases/:tag_name/assets/links/:link_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](../README.html#namespaced-path-encoding) . |
| `tag_name` | string | yes | 与发行版关联的标签. |
| `link_id` | integer | yes | 链接的 ID. |

请求示例：

```
curl --request DELETE --header "PRIVATE-TOKEN: n671WNGecHugsdEDPsyo" "https://gitlab.example.com/api/v4/projects/24/releases/v0.1/assets/links/1" 
```

响应示例：

```
{  "id":1,  "name":"new name",  "url":"http://192.168.10.15:3000",  "external":true,  "link_type":"other"  } 
```