【发布时间】:2017-04-25 00:04:30
【问题描述】:
我正在尝试将 MailChimp API 3.0 与 PHP 集成到自定义构建的 CMS 中。当我尝试使用以下代码创建一个广告系列时,我收到一条错误消息。
代码:
$apikey = <--api-key-->;
$list_id = <--list-id-->;
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp($apikey);
$result = $MailChimp->post("campaigns", [
'type' => 'regular',
'recipients' => ['list_id' => '$list_id'],
'settings' => ['subject_line' => 'test subject',
'reply_to' => 'test@test.com',
'from_name' => 'test name'],
]);
echo "<pre>";
print_r($result);
print_r($MailChimp->getLastRequest());
echo "</pre>";
错误信息:
Array
(
[type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/
[title] => Invalid Resource
[status] => 400
[detail] => The resource submitted could not be validated. For field-specific details, see the 'errors' array.
[instance] =>
[errors] => Array
(
[0] => Array
(
[field] =>
[message] => Schema describes object, NULL found instead
)
)
)
使用print_r($MailChimp->getLastRequest());
Array
(
[method] => post
[path] => campaigns
[url] => https://us8.api.mailchimp.com/3.0/campaigns
[body] =>
[timeout] => 10
[headers] => POST /3.0/campaigns HTTP/1.0
User-Agent: DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)
Host: us8.api.mailchimp.com
Accept-Encoding: deflate, gzip
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json
Authorization: apikey <--api-key-->
Content-Length: 0
)
我检查了documentation,通过 SO 搜索,但没有找到任何东西。如果有人有一个工作代码可以创建一个我可以开始使用的简单活动,我将不胜感激。我错过了什么?
【问题讨论】:
-
MailChimp 是 MailChip API 的官方分布式 PHP Rest 客户端的一部分吗?还是自行开发的课程?
-
你可以找到它here,它在MailChimp的文档中你可以使用它。
-
如那里所写,您可以使用
print_r($MailChimp->getLastRequest());来检查您发送的请求。将请求发送到 REST API 肯定有问题。 -
我用
getLastRequest()函数编辑了我的问题,我真的不知道要在其中查找什么... -
您的请求正文为 NULL。这就是错误的原因。 MailChimp API 期望 Body 中有一个 json 对象,其结构与您在其文档中已经看到的结构相同。
标签: php mailchimp mailchimp-api-v3.0