【问题标题】:Http 400 error when creating new Mailchimp list创建新的 Mailchimp 列表时出现 Http 400 错误
【发布时间】:2019-01-26 16:31:25
【问题描述】:

我正在尝试通过 mailchimp api 创建一个新列表,我已经尝试过多次调整代码但不断收到错误:

    {"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":"0174d737-b3d4-40a6-9cd4-e934ed8578a7","errors":[{"
field":"","message":"Schema describes object, NULL found instead"}]}

我的代码(api密钥有效):

$data = array( // the information for your new list--not all is required
        "name" => $name,
        "contact" => array (
            "company" => $company,
            "address1" => $address1
        ),
        "permission_reminder" => $permission_reminder,
        "use_archive_bar" => $archive_bars,
        "campaign_defaults" => array(
            "from_name" => $from_name,
            "from_email" => $from_email,
            "subject" => $subject,
            "language" => $language
        ),
        "notify_on_subscribe" => $notify_subs,
        "notify_on_unsubscribe" => $notify_unsubs,
        "email_type_option" => $type,
        "visibility" => $visibility
    );


    $ch = curl_init("https://$dataCenter.api.mailchimp.com/3.0/lists/");
    curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
    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, 'POST');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    print_r($result); // display API response

【问题讨论】:

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


    【解决方案1】:

    在您提供的代码中,我没有看到您的有效负载的任何 JSON 编码。您需要 json_encode() 您的有效负载 ($data) 以便 MailChimp 能够读取它。

    像这样: curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

    【讨论】:

      猜你喜欢
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 2017-03-23
      • 2012-12-18
      • 2021-12-10
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多