【问题标题】:How can I get interest groups from the MailChimp 3.0 API?如何从 MailChimp 3.0 API 获取兴趣组?
【发布时间】:2016-01-17 05:38:07
【问题描述】:

有谁知道获取 Mailchimp 3.0 API 中列表的所有兴趣组的正确端点是什么?我能找到的唯一文档在这里:https://github.com/mailchimp/APIv3-examples/wiki/Resources

当我尝试使用提到的/3.0/lists/{list_id}/interest-groupings 时,我得到以下响应:

类对象([type] => http://kb.mailchimp.com/api/error-docs/404-resource-not-found [title] => 找不到资源 [status] => 404 [detail] => 找不到资源“InterestGroupings_Collection”。[instance] =>)

请求的网址如下所示:https://DATA_CENTER.api.mailchimp.com/3.0/lists/LIST_ID/interest-groupings?apikey=API_KEY

我显然没有正确的端点,但我想我会问,因为我找到了我的另一个问题 here on SO 的答案。

【问题讨论】:

    标签: mailchimp


    【解决方案1】:

    虽然这是一个老问题,但我发布了这个答案,因为所选答案不再有效。 MailChimp 已停用建议的“API Playground”。

    我正在使用简单的 CURL 命令。您可以使用您正在使用的语言实现 CURL。 请注意,CURL 命令中的 ${dc} 将替换为您的 MailChimp 服务器前缀。

    1. 要做到这一点,首先你需要fetch/check the id of the list:

      curl -X GET \ 'https://${dc}.api.mailchimp.com/3.0/lists?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0&before_date_created=<SOME_STRING_VALUE>&since_date_created=<SOME_STRING_VALUE>&before_campaign_last_sent=<SOME_STRING_VALUE>&since_campaign_last_sent=<SOME_STRING_VALUE>&email=<SOME_STRING_VALUE>&sort_field=<SOME_STRING_VALUE>&sort_dir=<SOME_STRING_VALUE>&has_ecommerce_store=<SOME_BOOLEAN_VALUE>' \ --user "anystring:${apikey}"'

    2. 一旦你从上面的输出中得到指定的 ID ({list_id}),fetch the interest categories:

      curl -X GET \ 'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/interest-categories?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0&type=<SOME_STRING_VALUE>' \ --user "anystring:${apikey}"'

    3. 请注意上述输出中的{interest_category_id}。最后到get the interest details,使用:

      curl -X GET \ 'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/interest-categories/{interest_category_id}/interests?fields=<SOME_ARRAY_VALUE>&exclude_fields=<SOME_ARRAY_VALUE>&count=10&offset=0' \ --user "anystring:${apikey}"'

    一个示例 PHP 函数(仅适用于第 3 步)如下:

    function mailchimp_findgrpids()
        {
            $mcurl = 'https://'.MAILCHIMP_SERVER_PREFIX.'.api.mailchimp.com/3.0/lists/'.MAILCHIMP_LIST.'/interest-categories/'.MAILCHIMP_INTEREST_CAT.'/interests';
            
            $ch = curl_init($mcurl);
    
        curl_setopt($ch, CURLOPT_USERPWD, 'user:' . MAILCHIMP_API_KEY);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    
        $result = curl_exec($ch);
        echo $result;
        curl_close($ch);
        }
    

    【讨论】:

    • 感谢您的更新!超级有帮助,即使是一个 4 岁的问题。 :)
    【解决方案2】:

    您正在查看 Beta 版中严重过时的文档 - 您最好查看 API Playground,但您要查找的端点是 interest-categories

    【讨论】:

      猜你喜欢
      • 2019-08-29
      • 2017-04-29
      • 2015-08-19
      • 2016-09-15
      • 2016-04-17
      • 2012-02-04
      • 2013-09-16
      • 2015-12-10
      • 2016-08-18
      相关资源
      最近更新 更多