Tweets


使用此端点获取有关 Mautic 推文的详细信息。

Note

“推文”功能是 Mautic for Social 插件的一部分。要使此 API 正常工作,必须启用与 Twitter 的集成。

使用 Mautic API 库

您可以使用以下 :xref:`Mautic API Library 与此 API 进行交互,或者使用本文档中描述的各种 HTTP 端点。

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

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

获取推文

通过 ID 检索单个推文。

<?php

//...
$tweet = $tweetApi->get($id);

HTTP 请求

GET /tweets/ID

响应

  • 当请求成功检索到推文时,返回 200 OK

{
    "tweet": {
        "isPublished": true,
        "dateAdded": "2026-02-03T17:51:58+00:00",
        "dateModified": "2026-03-28T11:03:03+00:00",
        "createdBy": 1,
        "createdByUser": "John Doe",
        "modifiedBy": 1,
        "modifiedByUser": "John Doe",
        "id": 1,
        "name": "Thank you tweet",
        "text": "Hi {twitter_handle}\n\nThanks for ...",
        "description": "Used in the Product A campaign 1",
        "language": "en",
        "category": {
            "createdByUser": "John Doe",
            "modifiedByUser": null,
            "id": 185,
            "title": "Thank you tweets",
            "alias": "thank-you-tweets",
            "description": null,
            "color": "244bc9",
            "bundle": "global"
        },
        "mediaId": null,
        "mediaPath": null,
        "sentCount": 3,
        "favoriteCount": 0,
        "retweetCount": 0
    }
}

推文属性

    • Name
      • Type

      • Description

      • id

      • integer

      • ID of the Tweet

      • name

      • string

      • Title of the Tweet

      • text

      • string

      • Message content of the Tweet. Maximum 280 characters.

      • description

      • string

      • Internal description for the Tweet

      • isPublished

      • boolean

      • Tweet publication status

      • publishUp

      • datetime

      • Activation date and time for the Tweet

      • publishDown

      • datetime

      • Deactivation date and time for the Tweet

      • dateAdded

      • datetime

      • Tweet record creation date and time

      • createdBy

      • integer

      • ID of the User who created the Tweet

      • createdByUser

      • string

      • Name of the User who created the Tweet

      • dateModified

      • datetime

      • Tweet record last modification date and time

      • modifiedBy

      • integer

      • ID of the User who last modified the Tweet

      • modifiedByUser

      • string

      • Name of the User who last modified the Tweet

      • language

      • string

      • The language code for the Tweet, such as en, fr, and so on

      • category

      • object

      • The Category for the Tweet

      • mediaId

      • string

      • ID of the Twitter media object attached to the Tweet

      • mediaPath

      • string

      • Path to the local media file

      • sentCount

      • integer

      • Number of times this Tweet has been sent

      • favoriteCount

      • integer

      • Number of favorites or likes on the Tweet

      • retweetCount

      • integer

      • Number of retweets

List Tweets

Retrieves a list of Tweets.

<?php
// ...

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

HTTP request

GET /tweets

Query parameters

Name

Type

Description

search

string

String or search command to filter entities

start

integer

Starting row for the returned entities - defaults to 0

limit

integer

Maximum number of entities to return - defaults to 30

orderBy

string

Column to sort by. Any column in the response is valid.

Note: convert camelCase properties to snake_case. For example, dateAdded becomes date_added, and so on

orderByDir

string

Order direction - asc or desc

publishedOnly

boolean

Returns only currently published entities

minimal

boolean

Returns only a simple mapped object of entities without additional lists in it

Response

  • 当请求成功检索到推文列表时,返回 200 OK

{
    "total": 1,
    "tweets": [
        {
            "isPublished": true,
            "dateAdded": "2026-02-03T17:51:58+00:00",
            "dateModified": "2026-03-28T11:03:03+00:00",
            "createdBy": 1,
            "createdByUser": "John Doe",
            "modifiedBy": 1,
            "modifiedByUser": "John Doe",
            "id": 1,
            "name": "Thank you tweet",
            "text": "Hi {twitter_handle}\n\nThanks for ...",
            "description": "Used in the Product A campaign 1",
            "language": "en",
            "category": null,
            "mediaId": null,
            "mediaPath": null,
            "sentCount": 3,
            "favoriteCount": 0,
            "retweetCount": 0
        }
    ]
}

Properties

Name

Type

Description

total

integer

推文的总数。

tweets

array

推文对象的数组。

对于其他属性,请参考 推文属性

创建推文

创建一个新的推文。

<?php

$data = [
    'name' => 'Tweet A',
    'text' => 'This is my first tweet created via API.',
];

$tweet = $tweetApi->create($data);

HTTP 请求

POST /tweets/new

POST 参数

Name

Type

Description

name

string

推文的标题。 必填。

text

string

推文的消息内容。 最多 280 个字符。 必填。

description

string

推文的内部描述。

isPublished

boolean

推文的发布状态。

publishUp

datetime

推文的激活日期和时间。

publishDown

datetime

推文的停用日期和时间。

language

string

推文的语言代码,例如 enfr 等。

category

integer

推文所属类别的 ID。

asset

integer

与推文关联的资源的 ID。

page

integer

与推文关联的页面的 ID。

响应

  • 当请求成功创建推文时,返回 201 Created

响应是一个类似于 获取推文 的 JSON 对象。

Properties

请参考 推文属性

编辑推文

编辑一个推文。

此操作支持 PUTPATCH,具体取决于所需的行为:

  • PUT: 完全替换。如果 ID 不存在,则请求会创建一个新的推文。如果 ID 已存在,则请求会清除所有现有数据并用提供的值进行替换。

  • PATCH: 部分更新。该请求仅根据请求数据更新字段值。当推文 ID 不存在时,请求将失败。

<?php

$id   = 1;
$data = [
    'name' => 'Tweet A',
    'text' => 'This is my first tweet created via API.',
];

// 如果 ID 1 未找到,则创建新的推文
$createIfNotFound = true;

$tweet = $tweetApi->edit($id, $data, $createIfNotFound);

HTTP 请求

  • PUT /tweets/ID/edit: 更新现有的推文,或者当 ID 不存在时创建一个新的推文。

  • PATCH /tweets/ID/edit: 更新现有的推文。当 ID 不存在时,请求将失败。

POST 参数

接受与 创建推文 中描述的相同参数。所有参数都是可选的。

响应

  • PUT: 当请求成功更新推文时返回 200 OK,或者当请求创建推文时返回 201 Created

  • PATCH: 当请求成功更新推文时返回 200 OK,或者当推文 ID 不存在时返回 404 Not Found 错误。

响应是一个类似于 获取推文 的 JSON 对象。

属性

请参阅 推文属性.

删除推文

删除一个推文。

<?php

$tweet = $tweetApi->delete($id);

HTTP 请求

DELETE /tweets/ID/delete

响应

  • 当请求成功删除推文时,返回 200 OK

响应是一个包含已删除推文数据的 JSON 对象,类似于 获取推文

属性

请参阅 推文属性.