将 mailchimp 与 CRM 集成



需要用我所拥有的list_id campaign_id。我的目标是获取所有广告系列数据,然后使用list_id进行整理。我已经能够检索活动响应正文,但不知何故无法list_id活动。任何帮助或不同的方法将不胜感激。分享我的代码和邮件黑猩猩 API 相关参考。

邮件黑猩猩 API 参考:

"campaigns": [
{
"id": "42694e9e57",
"type": "regular",
"create_time": "2015-09-15T14:40:36+00:00",
"archive_url": "http://",
"status": "save",
"emails_sent": 0,
"send_time": "",
"content_type": "template",
"recipients": {
"list_id": "57afe96172",  // this is required
"segment_text": ""
},

我的进度:

public static function getCampaignID($list_id){
$MCcampaigninfo = self::$mc_api->get("/campaigns"); // gives a response consisting 3 rows, required value is in 1st row, which is an array
foreach ($MCcampaigninfo as $key => $value) {
if ($value[8]->'list_id' == $list_id) { //under the 'campaign'array, we need the 9th position property 'recipient'
$campaign_id = $value[12]->'id';
}
}
}

此代码假定$mc_api->get的响应等于您在示例中显示的 JSON

public static function getCampaignID($list_id) {
$campaigns = json_encode(self::$mc_api->get("/campaigns"), true);
$campaignIds = [];
foreach ($campaigns as $campaign) {
//if the list_id matches the current campaign recipients['list_id'] add to the array
if ($campaign['recipients']['list_id'] === $list_id) {
$campaignIds[] = $campaign['id'];
}
}
//return an array with campaignIds
return $campaignIds;
}

让它工作了。实际上,API 结构似乎与其文档不同。感谢您的所有帮助。发布我更新的代码。

public static function getCampaignID($list_id){
$MCcampaigninfo = self::$mc_api->get("/campaigns");     
foreach ($MCcampaigninfo as $key => $campaign) {
if($key == campaigns){
foreach ($campaign as $key2 => $clist) {
foreach ($clist as $key3 => $recip) {
if($key3 == id){
$campaign_id = $recip;
}
elseif($key3 == recipients){
foreach($recip as $key4 => $listid){
if($key4 == list_id){
if($listid == $list_id){
return $campaign_id;
}
}
}
}
}
}
}
}
}

最新更新