# Broadcast Messages API

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

*   [Get all broadcast messages](#get-all-broadcast-messages)
*   [Get a specific broadcast message](#get-a-specific-broadcast-message)
*   [Create a broadcast message](#create-a-broadcast-message)
*   [Update a broadcast message](#update-a-broadcast-message)
*   [Delete a broadcast message](#delete-a-broadcast-message)

# Broadcast Messages API[](#broadcast-messages-api "Permalink")

在 GitLab 8.12 中引入.

广播消息 API 对[广播消息进行操作](../user/admin_area/broadcast_messages.html) .

从 GitLab 12.8 开始，GET 请求不需要身份验证. 所有其他广播消息 API 终结点只能由管理员访问. 非 GET 请求者：

*   来宾将导致`401 Unauthorized` .
*   普通用户将导致`403 Forbidden` .

## Get all broadcast messages[](#get-all-broadcast-messages "Permalink")

列出所有广播消息.

```
GET /broadcast_messages 
```

请求示例：

```
curl "https://gitlab.example.com/api/v4/broadcast_messages" 
```

响应示例：

```
[  {  "message":"Example broadcast message",  "starts_at":"2016-08-24T23:21:16.078Z",  "ends_at":"2016-08-26T23:21:16.080Z",  "color":"#E75E40",  "font":"#FFFFFF",  "id":1,  "active":  false,  "target_path":  "*/welcome",  "broadcast_type":  "banner",  "dismissable":  false  }  ] 
```

## Get a specific broadcast message[](#get-a-specific-broadcast-message "Permalink")

获取特定的广播消息.

```
GET /broadcast_messages/:id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | yes | 要检索的广播消息的 ID. |

请求示例：

```
curl "https://gitlab.example.com/api/v4/broadcast_messages/1" 
```

响应示例：

```
{  "message":"Deploy in progress",  "starts_at":"2016-08-24T23:21:16.078Z",  "ends_at":"2016-08-26T23:21:16.080Z",  "color":"#cecece",  "font":"#FFFFFF",  "id":1,  "active":false,  "target_path":  "*/welcome",  "broadcast_type":  "banner",  "dismissable":  false  } 
```

## Create a broadcast message[](#create-a-broadcast-message "Permalink")

创建一个新的广播消息.

```
POST /broadcast_messages 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `message` | string | yes | 显示的消息. |
| `starts_at` | datetime | no | 开始时间（默认为当前时间）. |
| `ends_at` | datetime | no | 结束时间（默认为当前时间的一小时）. |
| `color` | string | no | 背景色十六进制代码. |
| `font` | string | no | 前景颜色十六进制代码. |
| `target_path` | string | no | 广播消息的目标路径. |
| `broadcast_type` | string | no | 外观类型（默认为横幅） |
| `dismissable` | boolean | no | 用户可以关闭该消息吗？ |

请求示例：

```
curl --data "message=Deploy in progress&color=#cecece" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/broadcast_messages" 
```

响应示例：

```
{  "message":"Deploy in progress",  "starts_at":"2016-08-26T00:41:35.060Z",  "ends_at":"2016-08-26T01:41:35.060Z",  "color":"#cecece",  "font":"#FFFFFF",  "id":1,  "active":  true,  "target_path":  "*/welcome",  "broadcast_type":  "notification",  "dismissable":  false  } 
```

## Update a broadcast message[](#update-a-broadcast-message "Permalink")

更新现有的广播消息.

```
PUT /broadcast_messages/:id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | yes | 要更新的广播消息的 ID. |
| `message` | string | no | 显示的消息. |
| `starts_at` | datetime | no | 起始时间. |
| `ends_at` | datetime | no | 结束时间. |
| `color` | string | no | 背景色十六进制代码. |
| `font` | string | no | 前景颜色十六进制代码. |
| `target_path` | string | no | 广播消息的目标路径. |
| `broadcast_type` | string | no | 外观类型（默认为横幅） |
| `dismissable` | boolean | no | 用户可以关闭该消息吗？ |

请求示例：

```
curl --request PUT --data "message=Update message&color=#000" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/broadcast_messages/1" 
```

响应示例：

```
{  "message":"Update message",  "starts_at":"2016-08-26T00:41:35.060Z",  "ends_at":"2016-08-26T01:41:35.060Z",  "color":"#000",  "font":"#FFFFFF",  "id":1,  "active":  true,  "target_path":  "*/welcome",  "broadcast_type":  "notification",  "dismissable":  false  } 
```

## Delete a broadcast message[](#delete-a-broadcast-message "Permalink")

删除广播消息.

```
DELETE /broadcast_messages/:id 
```

Parameters:

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer | yes | 要删除的广播消息的 ID. |

请求示例：

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