我正在尝试通过代码创建一个新的线索:
$url = "https://mysite/api/leads";
$data = array(
"first_name" => "John",
"last_name" => "Doe",
"email" => "[email protected]",
"phone" => "1234567890",
"company" => "Example Inc.",
"source" => "New Site",
"status" => "New"
);
$data_json = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authtoken: ".$api_key
));
$response = curl_exec($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status_code == 201) {
echo "New lead created successfully.";
} else {
echo "Error creating new lead. Status code: ".$status_code;
}
但 CRM 返回答案:
"status": false,
"error":
{ "name":"The Lead Name field is required.",
"source":"The Source field is required.",
"status":"The Status field is required."
},
"message": "The Lead Name field is required. The Source field is required. The Status field is required."
}
我不明白我的代码中的错误在哪里。该请求基于文档。
我不明白我的代码中的错误在哪里。
错误说:
"error":
{ "name":"The Lead Name field is required.",
"source":"The Source field is required.",
"status":"The Status field is required."
}
但是您的数据数组没有名称字段。应该是
$data = array(
"name" => "John Doe",
"email" => "[email protected]",
"phone" => "1234567890",
"company" => "Example Inc.",
"source" => "New Site",
"status" => "New"
);
此外,根据文档,成功的状态代码是 200 而不是 201。 因此这是不正确的..
if ($status_code == 201)
所以你在这之后成功了吗?我遇到了同样的问题,我正在遵循文档,但同样的错误也出现在我身上