【问题标题】:Integrating mailchimp with CRM将 mailchimp 与 CRM 集成
【发布时间】:2019-03-19 10:34:45
【问题描述】:

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

MailChimp 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';
        }
    }
}

【问题讨论】:

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


【解决方案1】:

此代码假定 $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;
}

【讨论】:

  • 我意识到这段代码可以工作。试过了,但输出与我的代码相同,crm 遇到 500 错误。谢谢。
  • 非常感谢您的帮助:)
【解决方案2】:

搞定了。 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;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

【讨论】:

  • 不要像这样使用嵌套的foreaches,按照我的方式编写,直接访问数组结构中的键(来自json)
猜你喜欢
  • 2017-04-23
  • 2014-04-06
  • 1970-01-01
  • 2016-06-01
  • 2016-01-10
  • 2021-02-25
  • 2010-11-18
  • 2011-02-25
  • 1970-01-01
相关资源
最近更新 更多