297.md 4.9 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
# 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" 
```