Mailchimp批处理呼叫返回0总计操作

时间:2019-03-18 22:36:38

标签: php mailchimp-api-v3.0

在Mailchimp中将联系人订阅到特定列表时,我整天都在努力工作,以使批量工作。当我尝试调用时,我得到以下响应,该响应说我的total_operations为0。关于从哪里开始找出我在做错什么的任何想法?任何帮助都可以使我免于精神错乱,我们将不胜感激!

这里是如何设置数据。我可以肯定这里的一切都是正确的。

$finalData = [];
foreach ($list_clean as $obj) {
    $individulData = array(
        'email_address' => $obj->email_address,
        'status'        => 'subscribed',
        'merge_fields'  => array(
            'FNAME' => $obj->first_name,
            'LNAME' => $obj->last_name
        )
    );

    $json_individulData        = json_encode($individulData);
    $finalData['operations'][] =
        array(
            "method" => "PUT",
            "path"   => "/lists/$mc_lid/members/" . md5(strtolower($obj->email_address)),
            "body"   => $json_individulData
        );
}

这将以以下格式返回数据:(修改后的日期内容,但结构相同)

{
  "operations": [
    {
      "method": "PUT",
      "path": "/lists/281c77a710/members/d83c093eb534d5c94169414a2477b13f",
      "body": "{\"email_address\":\"test1@example.com\",\"status\":\"subscribed\",\"merge_fields\":{\"FNAME\":\"Test\",\"LNAME\":\"One\"}}"
    },
    {
      "method": "PUT",
      "path": "/lists/281c77a710/members/c48dc4970fabd67cebd24b9102c1b38c",
      "body": "{\"email_address\":\"test2@example.com\",\"status\":\"subscribed\",\"merge_fields\":{\"FNAME\":\"Test\",\"LNAME\":\"Two\"}}"
    }
}

这是进行调用的函数。

function batchSubscribe(array $data, $key) {
    $auth          = base64_encode('user:' . $key);
    $json_postData = json_encode($data);
    console_log($json_postData);
    $ch            = curl_init();
    $dataCenter    = substr($key, strpos($key, '-') + 1);
    $curlopt_url   = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/batches/';
    curl_setopt($ch, CURLOPT_URL, $curlopt_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
        'Authorization: Basic ' . $auth));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_postData);

    $result = curl_exec($ch);
    return $result;
}

它不返回任何错误,但total_operations始终返回为0。这是完整的响应。

{
  "id": "dd9c7632ab",
  "status": "pending",
  "total_operations": 0,
  "finished_operations": 0,
  "errored_operations": 0,
  "submitted_at": "2019-03-18T22:18:56+00:00",
  "completed_at": "",
  "response_body_url": "",
  "_links": [
    {
      "rel": "parent",
      "href": "https://us20.api.mailchimp.com/3.0/batches",
      "method": "GET",
      "targetSchema": "https://us20.api.mailchimp.com/schema/3.0/Definitions/Batches/CollectionResponse.json",
      "schema": "https://us20.api.mailchimp.com/schema/3.0/CollectionLinks/Batches.json"
    },
    {
      "rel": "self",
      "href": "https://us20.api.mailchimp.com/3.0/batches/dd9c7632ab",
      "method": "GET",
      "targetSchema": "https://us20.api.mailchimp.com/schema/3.0/Definitions/Batches/Response.json"
    },
    {
      "rel": "delete",
      "href": "https://us20.api.mailchimp.com/3.0/batches/dd9c7632ab",
      "method": "DELETE"
    }
  ]
}

0 个答案:

没有答案