You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en_US/admin/api.md
+72-26
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,41 @@ The section introduces how to work with EMQX REST API.
10
10
11
11
EMQX has version control on the REST API, all API paths from EMQX 5.0.0 start with `/api/v5`.
12
12
13
+
## HTTP Headers
14
+
15
+
Most API requests require the `Accept` header to be set to `application/json`, and then the response will be returned in JSON format unless otherwise specified.
16
+
17
+
## HTTP Response Status Code
18
+
19
+
EMQX follows the [HTTP Response Status Code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) standard. The possible status codes are as follows:
| 200 | Request successfully, and the returned JSON data will provide more details |
24
+
| 201 | Created successfully, and the new object will be returned in the Body |
25
+
| 204 | Request successfully. Usually used for delete and update operations, and the returned Body will be empty |
26
+
| 400 | Bad Request. Usually request body or parameter error |
27
+
| 401 | Unauthorized. API key expires or does not exist. |
28
+
| 403 | Forbidden. Check if the object is in use or has dependency constraints. |
29
+
| 404 | Not Found. You can refer to the `message` field in the Body to check the reason |
30
+
| 409 | Conflict. The object already exists or the number limit is exceeded |
31
+
| 500 | Internal Server Error. Check the reason in the Body and logs |
32
+
13
33
## Authentication
14
34
15
-
EMQX's REST API uses [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#the_general_http_authentication_framework) with API keys as authentication credentials. Before using the EMQX REST API, you need to create an API key.
35
+
EMQX's REST API supports two main methods for authentication: basic Authentication using API keys and bearer token authentication.
36
+
37
+
### Basic Authentication Using API Keys
38
+
39
+
In this method, you use API keys and secret keys as the username and password to authenticate your API requests. EMQX's REST API follows [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#the_general_http_authentication_framework), where these credentials are required. Before using the EMQX REST API, you must create an API key.
40
+
41
+
::: tip Note
42
+
43
+
For security reasons, starting from EMQX 5.0.0, you cannot use Dashboard user credentials to authenticate REST API requests. Instead, you need to create and use API keys for authentication. Note that role-based API credentials are available only in the EMQX Enterprise edition.
16
44
17
-
:::tip
18
-
For security reasons, from EMQX 5.0.0 onwards, Dashboard users cannot be used for REST API authentication. Role-based API credentials are a feature of the EMQX Enterprise edition.
19
45
:::
20
46
21
-
### Create API Keys
47
+
####Create API Keys
22
48
23
49
You can manually create API keys for authentication on the Dashboard by navigating to **System** -> **API Key**. For instructions, see [System - API Keys](../dashboard/system.md#api-keys).
24
50
@@ -32,9 +58,9 @@ api_key = {
32
58
33
59
In the specified file, add multiple API keys in the format `{API Key}:{Secret Key}:{?Role}`, separated by new lines:
34
60
35
-
- API Key: Any string as the key identifier.
36
-
- Secret Key: Use a random string as the secret key.
37
-
- Role (optional): Specify the key's [role](#roles-and-permissions), applicable only in the Enterprise edition.
61
+
-**API Key**: Any string as the key identifier.
62
+
-**Secret Key**: Use a random string as the secret key.
63
+
-**Role (optional)**: Specify the key's [role](#roles-and-permissions), applicable only in the Enterprise edition.
38
64
39
65
For example:
40
66
@@ -48,17 +74,19 @@ API keys created this way are valid indefinitely.
48
74
49
75
Each time EMQX starts, it will add the data set in the file to the API key list. If an API key already exists, its Secret Key and Role will be updated.
50
76
51
-
### Roles and Permissions
77
+
####Roles and Permissions (Enterprise Edition)
52
78
53
-
In the EMQX Enterprise edition, the REST API implements role-based access control. When creating an API key, you can assign one of the following 3 predefined roles:
79
+
In the EMQX Enterprise edition, the REST API implements role-based access control. When creating an API key, you can assign one of the following three predefined roles:
54
80
55
81
-**Administrator**: This role can access all resources and is the default value if no role is specified. The corresponding role identifier is `administrator`.
56
82
-**Viewer**: This role can only view resources and data, corresponding to all GET requests in the REST API. The corresponding role identifier is `viewer`.
57
83
-**Publisher**: Designed specifically for MQTT message publishing, this role is limited to accessing APIs related to message publishing. The corresponding role identifier is `publisher`.
58
84
59
-
### Authentication Method
85
+
#### Authentication Method Using API Keys
86
+
87
+
Once you have your API key and secret key, you can use them to authenticate your requests. The API key is used as the username and the secret key as the password for Basic Authentication.
60
88
61
-
You can use the generated API Key and Secret Key as the username and password for Basic authentication:
89
+
Examples in different languages:
62
90
63
91
:::: tabs type:card
64
92
:::tab cURL
@@ -203,25 +231,43 @@ axios
203
231
:::
204
232
::::
205
233
206
-
##HTTP Headers
234
+
### Authentication Using Bearer Token
207
235
208
-
Unless otherwise specified, most API requests require the `Accept` header to be set to `application/json`, and then the response will be returned in JSON format.
236
+
As an alternative to API key-based authentication, you can use bearer tokens for secure and programmatic access to the EMQX REST API. To obtain a bearer token, send a request to the login API endpoint as described below.
209
237
210
-
##HTTP Response Status Code
238
+
#### Obtain a Bearer Token
211
239
212
-
EMQX follows the [HTTP Response Status Code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) standard, and the possible status codes are as follows:
240
+
To request a bearer token, make an HTTP`POST` request to the following login API endpoint:
Copy file name to clipboardExpand all lines: en_US/dashboard/system.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ On the API Keys page, you can generate an API key and secret key for accessing t
39
39
40
40
1. Click the **+ Create** button on the top right corner of the page to bring up the Create API Key pop-up dialog.
41
41
42
-
2. On the Create API Key dialog, configure in the detailed information for the API key.
42
+
2. On the Create API Key dialog, configure the detailed information for the API key.
43
43
44
44
- The API key will never expire if the Expire At box is left empty.
45
45
- Select a role for API key (optional), applicable only in the Enterprise edition. For more information about roles, see [Roles and Permissions](../admin/api.md#roles-and-permissions).
| 404 | 找不到请求路径或请求的对象不存在,可参照 Body 中的 `message` 字段判断具体原因 |
30
+
| 409 | 请求的资源已存在或数量超过限制 |
31
+
| 500 | 服务端处理请求时发生内部错误,可通过 Body 返回内容与日志判断具体原因 |
32
+
13
33
## 认证
14
34
15
-
EMQX 的 REST API 使用 [HTTP Basic 认证](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Authentication#%E9%80%9A%E7%94%A8%E7%9A%84_http_%E8%AE%A4%E8%AF%81%E6%A1%86%E6%9E%B6) 携带 API 密钥作为认证凭据。在开始使用 EMQX REST API 之前,您需要创建 API 密钥。
35
+
EMQX 的 REST API 支持两种主要的认证方法:使用 API 密钥的基本认证和 Bearer Token 认证。
36
+
37
+
### 使用 API 密钥的基本认证
16
38
17
-
::: tip
18
-
出于安全考虑,从 EMQX 5.0.0 开始 Dashboard 用户无法用于 REST API 认证。
19
-
API 凭证区分角色是 EMQX 企业版中的功能。
39
+
在这种方法中,您通过使用 API 密钥和密钥作为用户名和密码来对 API 请求进行身份验证。EMQX 的 REST API 基于 HTTP 基本认证框架,要求提供这些凭据。使用 EMQX REST API 之前,您需要先创建一个 API 密钥。
40
+
41
+
::: tip 注意
42
+
出于安全考虑,从 EMQX 5.0.0 开始 Dashboard 用户凭据无法用于 REST API 认证。您需要创建并使用 API 密钥进行认证。请注意,基于角色的 API 凭据仅适用于 EMQX 企业版。
20
43
:::
21
44
22
-
### 创建 API 密钥
45
+
####创建 API 密钥
23
46
24
47
您可以在 Dashboard **系统设置** -> **API 密钥** 页面中手动创建用于认证的 API 密钥,详细操作请参考 [Dashboard - API 密钥](../dashboard/system.md#api-密钥)。
25
48
@@ -33,9 +56,9 @@ api_key = {
33
56
34
57
在指定的文件中通过多行分割的 `{API Key}:{Secret Key}:{?Role}` 的格式添加多个 API 密钥:
Copy file name to clipboardExpand all lines: zh_CN/data-integration/data-bridge-mysql.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ MySQL 数据集成是 EMQX 企业版功能。
6
6
7
7
:::
8
8
9
-
[MySQL](https://www.mysql.com/) 是一个广泛使用的关系数据库,具备高度的可靠性和稳定性,能够快速安装和配置使用。MySQL Sink 能够将 MQTT 消息高效地存储至 MySQL 数据库中,同时也支持通过事件触发实时更新或删除 MySQL 中的数据。借助 MySQl 数据集成,用户能够轻松实现消息存储、设备在线状态更新以及设备行为记录等功能,实现灵活的物联网数据存储与设备管理功能。
9
+
[MySQL](https://www.mysql.com/) 是一个广泛使用的关系数据库,具备高度的可靠性和稳定性,能够快速安装和配置使用。MySQL Sink 能够将 MQTT 消息高效地存储至 MySQL 数据库中,同时也支持通过事件触发实时更新或删除 MySQL 中的数据。借助 MySQL 数据集成,用户能够轻松实现消息存储、设备在线状态更新以及设备行为记录等功能,实现灵活的物联网数据存储与设备管理功能。
0 commit comments