I'm trying to integrate the MailChimp API 3.0 with PHP into a custom built CMS. When I try to create a single campaign with the following code I have an error message.
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>";
ERROR MESSAGE:
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
)
)
)
USING 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
)
I have checked the documentation, searched through SO, but haven't found anything. If anyone has a working code that creates a simple campaign I can start working with, I would appreciate it. What am I missing?