无法创建广告系列Mailchimp API 3.0 - PHP

时间:2016-12-09 13:30:08

标签: php mailchimp mailchimp-api-v3.0

我尝试将MailChimp API 3.0与PHP集成到自定义构建的CMS中。当我尝试使用以下代码创建单个广告系列时,我收到了错误消息。

CODE:

$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,但没有找到任何内容。如果有人有一个工作代码可以创建一个我可以开始使用的简单广告系列,我将不胜感激。我错过了什么?

1 个答案:

答案 0 :(得分:1)

这是我用来完成它的代码,也检查编码,它可能会导致问题

$result = $MailChimp->post("campaigns", [
                           "type" =>"regular",
                               "recipients"=> [
                                   "list_id"=> "$list_id"
                                   ]
                               ,
                               "settings"=> [
                                   "subject_line"=> "test subject",
                                   "from_name"=> "test name",
                                   "reply_to"=> "test@test.com"
                               ]
                           ]);