Users
使用此端点来操作并获取有关 Mautic 用户详情。
使用 Mautic API 库
您可以使用 :xref:`Mautic API 库 与此 API 进行交互,如下所示,也可以使用本文档中描述的各种 HTTP 端点。
<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;
// ...
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = "https://example.com";
$api = new MauticApi();
$userApi = $api->newApi("users", $auth, $apiUrl);
获取用户
检索单个用户。
<?php
//...
$user = $userApi->get($id);
HTTP 请求
GET /users/ID
响应
当请求成功检索到用户时,返回
200 OK。
{
"user": {
"isPublished": true,
"dateAdded": "2026-02-21T05:19:56+00:00",
"dateModified": "2026-02-21T05:20:13+00:00",
"createdBy": 1,
"createdByUser": "Admin Mautic",
"modifiedBy": 1,
"modifiedByUser": "Admin Mautic",
"id": 3,
"username": "r.green",
"firstName": "Rachel",
"lastName": "Green",
"email": "rachel.green@acme.com",
"position": "Marketing Staff",
"role": {
"createdByUser": "Admin Mautic",
"modifiedByUser": null,
"id": 2,
"name": "Email Permissions",
"description": null,
"isAdmin": false,
"rawPermissions": {
"email:categories": [
"full"
],
"email:emails": [
"full"
]
}
},
"timezone": "Europe/Paris",
"locale": null,
"lastLogin": "2026-02-22T04:28:00+00:00",
"lastActive": "2026-02-22T04:28:00+00:00",
"signature": "Best regards, \r\nRachel Green"
}
}
用户属性
- Name
Type
Description
isPublishedboolean
用户发布状态
dateAddeddatetime
用户记录创建日期和时间
dateModifieddatetime
用户记录上次修改日期和时间
createdByinteger
创建用户记录的用户的 ID
createdByUserstring
创建用户记录的用户姓名
modifiedByinteger
最后修改用户记录的用户的 ID
modifiedByUserstring
最后修改用户记录的用户姓名
idinteger
用户的 ID
usernamestring
用于登录的用户名 - 唯一
firstNamestring
用户的姓氏
lastNamestring
用户的名
emailstring
用户的电子邮件地址 - 唯一
positionstring
用户的职位或职称
roleobject
分配给用户的角色和权限。请参阅 用户角色属性 以获取详细信息
timezonestring
用户的时区偏好
localestring
用户的语言或地区偏好
lastLogindatetime
上次登录的日期和时间
lastActivedatetime
上次活动的时间
signaturestring
HTML 格式的电子邮件签名
用户角色属性
Name |
Type |
Description |
|---|---|---|
|
boolean |
角色发布状态 |
|
datetime |
角色记录创建日期和时间 |
|
datetime |
角色记录上次修改日期和时间 |
|
integer |
创建角色记录的用户的 ID |
|
string |
创建角色记录的用户姓名 |
|
integer |
最后修改角色记录的用户的 ID |
|
string |
最后修改角色记录的用户姓名 |
|
integer |
角色的 ID |
|
string |
角色的名称 |
|
string |
角色的描述 |
|
boolean |
管理员状态 - 如果角色具有完全系统访问权限,则为 |
|
object |
用于 Mautic 模块的细粒度权限集合 |
列出用户
检索用户列表。
<?php
//...
$users = $userApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);
HTTP 请求
GET /users
查询参数
Name |
Type |
Description |
|---|---|---|
|
string |
用于过滤实体的字符串或搜索命令 |
|
integer |
返回实体的起始行,默认为 0 |
|
integer |
要返回的最大实体数量,默认为 30 |
|
string |
用于排序的列。响应中的任何列都有效。 注意: 将 |
|
string |
排序方向,可以是 |
|
boolean |
仅返回当前已发布的实体 |
|
boolean |
仅返回简单的实体映射对象,不包含其他列表 |
响应
当请求成功检索到用户列表时,返回
200 OK。
{
"total": 3,
"users": [
{
"isPublished": true,
"dateAdded": "2026-02-21T05:19:56+00:00",
"dateModified": "2026-02-21T05:20:13+00:00",
"createdBy": 1,
"createdByUser": "Admin Mautic",
"modifiedBy": 1,
"modifiedByUser": "Admin Mautic",
"id": 3,
"username": "r.green",
"firstName": "Rachel",
"lastName": "Green",
"email": "rachel.green@acme.com",
"position": "Marketing Staff",
"role": {
"createdByUser": "Admin Mautic",
"modifiedByUser": null,
"id": 2,
"name": "Email Permissions",
"description": null,
"isAdmin": false,
"rawPermissions": {
"email:categories": [
"full"
],
"email:emails": [
"full"
]
}
},
"timezone": "Europe/Paris",
"locale": null,
"lastLogin": "2026-02-22T04:28:00+00:00",
"lastActive": "2026-02-22T04:28:00+00:00",
"signature": "Best regards, \r\nRachel Green"
},
// ...
]
}
属性
Name |
Type |
Description |
|---|---|---|
|
integer |
用户总数 |
|
array |
用户数组 |
对于其他属性,请参阅 User properties.
创建用户
创建一个新用户。
<?php
$data = array(
'firstName' => 'John', // Required
'lastName' => 'Doe', // Required
'username' => 'newuser', // Required
'email' => 'john.doe@example.com', // Required
'plainPassword' => array( // Required
'password' => 'SecurePassword123!',
'confirm' => 'SecurePassword123!'
),
'role' => 1, // Required
'timezone' => 'America/New_York', // Required
'locale' => 'en_US', // Required
'position' => 'Marketing Specialist',
);
$user = $userApi->create($data);
HTTP request
POST /users/new
POST 参数
Name |
Type |
Description |
|---|---|---|
|
string |
Required. 用户的姓氏 |
|
string |
Required. 用户的名 |
|
string |
Required. Must be unique. 用于登录的用户名 |
|
string |
Required. Must be unique. 用户的电子邮件地址 |
|
array |
Required. 包含 password 和 confirm 键的数组 |
|
integer |
Required. 分配给用户的角色的 ID |
|
string |
Required. 用户的时区偏好 |
|
string |
Required. 用户的语言或区域设置偏好 |
|
boolean |
用户发布状态。设置为 0 或 false 以禁用用户帐户,默认为 1 |
|
string |
职位或职称 |
|
string |
HTML 格式的电子邮件签名 |
Response
当请求成功创建用户时,返回 201 Created。
响应是一个类似于 Get User 的 JSON 对象。
Properties
请参阅 User properties.
Edit User
编辑用户。
此操作支持 PUT 或 PATCH,具体取决于所需的行为:
PUT: 完全替换。如果 ID 缺失,则请求会创建一个新用户。如果 ID 存在,则请求会清除所有现有数据并将其替换为提供的值。
PATCH: 部分更新。该请求仅根据请求数据更新字段值。当用户 ID 不存在时,该请求将失败。
- $id = 1;
- $data = array(
‘firstName’ => ‘John Updated’, ‘position’ => ‘Senior Marketing Specialist’, ‘timezone’ => ‘Europe/London’
);
// Create a new User if ID 1 isn’t found $createIfNotFound = true;
$user = $userApi->edit($id, $data, $createIfNotFound);
HTTP request
PUT /users/ID/edit: updates an existing User or creates a new one when the ID doesn’t exist.PATCH /users/ID/edit: updates an existing User. The request fails when the ID doesn’t exist.
POST parameters
Accepts the same parameters as those described in Create User. All parameters are optional.
Response
PUT: returns200 OKwhen the request successfully updates the User or201 Createdwhen the request creates a User.PATCH: returns200 OKwhen the request successfully updates the User or404 Not Founderror when the User ID doesn’t exist.
The response is a JSON object similar to Get User.
Properties
Refer to User properties.
Delete User
Deletes a User.
<?php
$user = $userApi->delete($id);
HTTP request
DELETE /users/ID
Response
Returns
200 OKwhen the request successfully deletes the User.
The response is a JSON object containing the data of the deleted User, similar to Get User.
Properties
Refer to User properties.
Get current User
Retrieves the profile data of the User associated with the current API credentials.
<?php
$currentUser = $userApi->getSelf();
HTTP request
GET /users/self
Response
Returns
200 OKwhen the request successfully retrieves the User’s information.
- {
“isPublished”: true, “dateAdded”: “2026-02-21T05:19:56+00:00”, “dateModified”: “2026-02-21T05:20:13+00:00”, “createdBy”: 1, “createdByUser”: “Admin Mautic”, “modifiedBy”: 1, “modifiedByUser”: “Admin Mautic”, “id”: 3, “username”: “r.green”, “firstName”: “Rachel”, “lastName”: “Green”, “email”: “rachel.green@acme.com”, “position”: “Marketing Staff”, “role”: {
“isPublished”: true, “dateAdded”: “2026-02-21T05:18:04+00:00”, “dateModified”: “2026-02-23T04:02:22+00:00”, “createdBy”: 1, “createdByUser”: “Admin Mautic”, “modifiedBy”: 1, “modifiedByUser”: “John Doe”, “id”: 2, “name”: “Email Permissions”, “isAdmin”: false, “rawPermissions”: {
- “asset:categories”: [
“view”, “edit”, “create”, “delete”
], “asset:assets”: [
“viewown”, “editown”, “create”, “deleteown”
], “email:categories”: [
“full”
], “email:emails”: [
“full”
], “mauticSocial:categories”: [
“full”
], “mauticSocial:monitoring”: [
“full”
], “mauticSocial:tweets”: [
“viewown”, “editown”, “create”, “deleteown”, “publishown”
]
}
}, “timezone”: “Europe/Paris”, “lastLogin”: “2026-02-25T08:24:46+00:00”, “lastActive”: “2026-02-25T08:24:46+00:00”, “signature”: “Best regards, rnRachel Green”
}
当前用户属性
- Name
Type
Description
isPublishedboolean
用户发布状态
dateAddeddatetime
用户记录创建日期和时间
dateModifieddatetime
用户记录上次修改日期和时间
createdByinteger
创建用户记录的用户的 ID
createdByUserstring
创建用户记录的用户姓名
modifiedByinteger
上次修改用户记录的用户的 ID
modifiedByUserstring
上次修改用户记录的用户姓名
idinteger
用户的 ID
usernamestring
用于登录的用户名 - 唯一
firstNamestring
用户的姓氏
lastNamestring
用户的名
emailstring
用户的电子邮件地址 - 唯一
positionstring
用户的职位或职称
roleobject
分配给用户的角色和权限
timezonestring
用户的时区偏好
lastLogindatetime
上次登录的日期和时间
lastActivedatetime
上次活动的时间
signaturestring
HTML 格式的电子邮件签名
当前用户角色属性
Name |
Type |
Description |
|---|---|---|
|
boolean |
角色的发布状态 |
|
datetime |
角色记录创建日期和时间 |
|
datetime |
角色记录上次修改日期和时间 |
|
integer |
创建角色记录的用户的 ID |
|
string |
创建角色记录的用户姓名 |
|
integer |
上次修改角色记录的用户的 ID |
|
string |
上次修改角色记录的用户姓名 |
|
integer |
角色的 ID |
|
string |
角色的名称 |
|
string |
角色的描述 |
|
boolean |
管理员状态 - 如果角色具有完全系统访问权限,则为 |
|
object |
用于 Mautic 模块的细粒度权限集合 |
验证用户权限
验证用户是否具有特定权限。
<?php
$permissions = array('user:users:view', 'user:users:edit'); // Required
$result = $userApi->checkPermission($userId, $permissions);
HTTP 请求
POST /users/ID/permissioncheck
POST 参数
Name |
Type |
Description |
|---|---|---|
|
array |
Required. 用于验证的权限字符串数组。 |
Response
当请求成功验证用户时,返回
200 OK。
{
"user:users:view": true,
"user:users:edit": true
}
Properties
Name |
Type |
Description |
|---|---|---|
|
boolean |
权限状态 - |
Note
bundle: Mautic bundle 的名称,例如:user、email、asset等。group: bundle 中的功能组,例如:users、roles、forms等。action: 具体的操作,例如:view、edit、create、delete或full。
列出用户角色
检索所有可用的用户角色。
<?php
$roles = $userApi->getRoles();
HTTP 请求
GET /users/list/roles
查询参数
Name |
Description |
|---|---|
|
用于按名称过滤角色的字符串。 |
|
返回的角色数量限制。 |
Response
当请求成功检索用户角色列表时,返回
200 OK。
[
{
"id": 1,
"name": "Administrator"
},
{
"id": 2,
"name": "Email Permissions"
}
]
Properties
Name |
Type |
Description |
|---|---|---|
|
integer |
角色的 ID。 |
|
string |
分配给角色的名称。 |
错误响应
常见错误响应
HTTP code |
Error status |
Description |
|---|---|---|
|
Bad Request |
表示无效的 JSON 语法或字段验证失败。例如:缺少必需字段、密码强度不足或用户名重复。 |
|
Unauthorized |
需要身份验证,或者检测到密码强度不足。 |
|
Forbidden |
没有执行此操作的权限。 |
|
Not Found |
未找到具有指定 ID 的用户。 |
|
Internal server error |
发生意外错误,通常是由于请求正文中存在无效的数据格式。 |
密码验证错误
在创建或更新用户时发生的密码验证错误:
- {
- “errors”: [
- {
“code”: 400, “message”: “password: Please enter a stronger password. Your password must use a combination of upper and lower case, special characters and numbers.”, “details”: {
- “password”: [
“Please enter a stronger password. Your password must use a combination of upper and lower case, special characters and numbers.”
]
}
}
]
}
Permission error
Permission error for non-existent Users:
{
"errors": [
{
"code": 404,
"message": "Item was not found.",
"details": []
}
]
}
Role assignment error
Error when assigning User’s Role:
{
"errors": [
{
"code": 400,
"message": "role: This value is not valid.",
"details": {
"role": [
"This value is not valid."
]
}
}
]
}