我尝试在自定义Drupal模块中使用Mailchimp PHP API创建广告系列,但我无法使用现有模板。
我确定请求中的模板ID,但响应中的id始终为0.
重用模板的正确请求有效负载是什么?
我只想重用一个非常简单的模板。目前,该广告系列没有特定的文字,当我能够使用正确的模板时,我会尝试插入文字模式。
提前致谢。
这是我目前的代码:
function mymodule_templates_list()
{
$mailchimpPath = realpath(__DIR__ . '/../../libraries/mailchimp');
require_once $mailchimpPath . '/src/Mailchimp.php';
require_once $mailchimpPath . '/src/Mailchimp/Templates.php';
$mailchimp = new Mailchimp('my-api-key');
$templatesService = new Mailchimp_Templates($mailchimp);
$list = $templatesService->getList(
array(
'user' => true,
'gallery' => false,
'base' => false,
),
array(
'include_drag_and_drop' => true,
)
);
dpm($list); // just to verify the template ID
$campaignService = new Mailchimp_Campaigns($mailchimp);
$response = $campaignService->getList();
dpm($response);
$options = array(
"list_id" => 'my-list-id', // this is OK, correct list used in the response
"subject" => "My subject", // OK
"from_email" => "mymail@dev.null", // OK
"from_name" => "Site name", // OK
"to_name" => '',
'template_id' => 123456, // KO : 0 in the response
);
$content = array(
"text" => "dunno what to use here",
"url" => 'dunno what to use here',
"archive" => "dunno what to use here",
);
$response = $campaignService->create('regular', $options, $content);
dpm($response);
return '';
}