Notifications

Note

此页面的内容需要进行重大更新。旧页面包含过时且可能不准确的信息。您仍然可以在 Mautic Developer Documentation archived repository 中访问它。

如果您有兴趣帮助开发此页面和其他新内容的,请考虑加入文档编写工作。

请阅读 Contributing GuidelinesContributing to Mautic’s documentation 以开始您的贡献。

使用此端点获取有关 Mautic 通知的信息。

<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;

// ...
$initAuth        = new ApiAuth();
$auth            = $initAuth->newAuth($settings);
$apiUrl          = "https://example.com";
$api             = new MauticApi();
$notificationApi = $api->newApi("notifications", $auth, $apiUrl);

获取通知

<?php

//...
$notification = $notificationApi->get($id);

通过 ID 获取单个通知。

HTTP 请求

GET /notifications/ID

响应

Expected Response Code: 200

{
    "notification":{
        "isPublished":true,
        "dateAdded":"2016-09-14T14:03:05+00:00",
        "createdBy":1,
        "createdByUser":"John Doe",
        "dateModified":"2016-09-15T08:40:46+00:00",
        "modifiedBy":1,
        "modifiedByUser":"John Doe",
        "id":1,
        "name":"The first notification",
        "heading":"The first notification Heading",
        "message":"The first notification Message",
        "url":"http:\/\/mautic.org",
        "language":"en",
        "category":null,
        "publishUp":null,
        "publishDown":null,
        "readCount":0,
        "sentCount":0
    }
}

通知属性

    • Name
      • Type

      • Description

      • id

      • int

      • 通知 ID

      • name

      • string

      • 通知标题

      • heading

      • string

      • 通知头部

      • message

      • string

      • 通知内容

      • url

      • string

      • 当点击通知时跳转的 URL

      • isPublished

      • boolean

      • 发布状态

      • publishUp

      • datetime/null

      • 通知发布日期/时间

      • publishDown

      • datetime/null

      • 通知取消发布日期/时间

      • dateAdded

      • datetime

      • 创建通知的日期/时间

      • createdBy

      • int

      • 创建通知的用户 ID

      • createdByUser

      • string

      • 创建通知用户的姓名

      • dateModified

      • datetime/null

      • 最后修改通知的日期/时间

      • modifiedBy

      • int

      • 最后修改通知的用户 ID

      • modifiedByUser

      • string

      • 最后修改通知用户的姓名

      • language

      • string

      • 语言区域设置

      • readCount

      • int

      • 通知总阅读次数

      • sentCount

      • int

      • 唯一通知发送次数

      • category

      • null/object

      • 分类

列出通知

<?php
// ...

$notifications = $notificationApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);

HTTP 请求

GET /notifications

查询参数

Name

Description

search

用于过滤实体的字符串或搜索命令。

start

返回实体的起始行。默认为 0。

limit

要返回的实体数量限制。默认为分页系统的配置 - 默认为 30

orderBy

用于排序的列。可以使用响应中列出的任何列。

orderByDir

排序方向:ascdesc

publishedOnly

仅返回当前已发布的实体。

minimal

仅返回实体数组,不包含其他列表。

响应

Expected Response Code: 200


```json {

“total”:1, “notifications”:[

{

“isPublished”:true, “dateAdded”:”2016-09-14T14:03:05+00:00”, “createdBy”:1, “createdByUser”:”John Doe”, “dateModified”:”2016-09-15T08:40:46+00:00”, “modifiedBy”:1, “modifiedByUser”:”John Doe”, “id”:1, “name”:”The first notification”, “heading”:”The first notification Heading”, “message”:”The first notification Message”, “url”:”http://mautic.org”, “language”:”en”, “category”:null, “publishUp”:null, “publishDown”:null, “readCount”:0, “sentCount”:0

}

]

}

Properties

Same as Get Notification.

Create notification

<?php

$data = array(
    'name'    => 'Notification A',
    'heading' => 'Hello World!'
    'message' => 'This is my first notification created via API.',
);

$notification = $notificationApi->create($data);

Create a new notification.

HTTP Request

POST /notifications/new

POST Parameters

Name

Type

Description

id

int

ID of the notification

name

string

Title of the notification

heading

string

Heading of the notification

message

string

Message of the notification

url

string

URL to go to when the notification gets clicked

isPublished

boolean

Published state

publishUp

datetime/null

Notification publish date/time

publishDown

datetime/null

Notification unpublish date/time

language

string

Language locale of the notification

Response

Expected Response Code: 201

Properties

Same as Get Notification.

Edit notification

<?php

$id   = 1;
$data = array(
    'name'    => 'Notification A',
    'heading' => 'Hello World!'
    'message' => 'This is my first notification created via API.',
);

// Create new a notification of ID 1 isn't found?
$createIfNotFound = true;

$notification = $notificationApi->edit($id, $data, $createIfNotFound);

Edit a new notification. Note that this supports PUT or PATCH depending on the desired behavior.

PUT creates a notification if the given ID doesn’t exist and clears all the notification information, adds the information from the request. PATCH fails if the notification with the given ID doesn’t exist and updates the notification field values with the values from the request.

HTTP Request

```

要编辑通知并返回 404 错误(如果未找到该通知):

PATCH /notifications/ID/edit

要编辑通知,如果未找到该通知,则创建一个新通知:

PUT /notifications/ID/edit

POST 参数

Name

Type

Description

id

int

通知 ID

name

string

通知标题

heading

string

通知头部

message

string

通知消息

url

string

当点击通知时跳转的 URL

isPublished

boolean

发布状态

publishUp

datetime/null

通知发布日期/时间

publishDown

datetime/null

通知取消发布日期/时间

language

string

语言本地化设置

响应

如果使用 PUT,则预期响应代码为 `200`(如果已编辑通知)或 `201`(如果已创建)。

如果使用 PATCH,则预期响应代码为 200

属性

Get Notification

删除通知

<?php

$notification = $notificationApi->delete($id);

删除一个通知。

HTTP 请求

DELETE /notifications/ID/delete

响应

Expected Response Code: 200

属性

Get Notification