我想使用api v2在zoho crm中插入数据。首先创建一个数组,然后对json进行编码。请求url https://www.zohoapis.com/crm/v2/Contacts 。 但是我遇到了这个错误。
代码:
$authtoken = ***********;
$fields={"data":["{\"Last_Name\":\"Test John insert\",\"Email\":\"testjhon@jhon.com\"}"]};
$zoho_url = "https://www.zohoapis.com/crm/v2/Contacts";
错误:
{"data":[{"code":"INVALID_DATA","details":{"expected_data_type":"jsonobject","index":0},"message":"invalid data","status":"error"}]}
答案 0 :(得分:0)
使用此json数组:
$fields = "{\"data\":[{\"Last_Name\": \"Test\",\"First_Name\": \"TESTING\",\"Email\": \"demo@w3scloud.com\"}],\"trigger\":[\"approval\",\"workflow\"]}";
答案 1 :(得分:0)
我注意到Zoho似乎想要在数据周围再加上一个括号。而且,您可以尝试在将数据数组发送到cURL之前,将数据数组编码为JSON字符串 。
$fields = json_encode([
["data" => ["Last_Name" => "Test John insert","Email" => "testjhon@jhon.com"]],
]);
如@Ghost所述,您可能还需要更改内容类型。根据{{3}},将数组传递给CURLOPT_POSTFIELDS
会将内容类型设置为multipart/form-data
;您可能想要的是application/json
。
CURLOPT_HTTPHEADER => array(
"Authorization: ".$authtoken,
"Content-Type: application/json"
),
答案 2 :(得分:0)
以这种方式发送:
[{ "data": \[ { "Company":"company name", "Last_Name":"your last name", "Phone":"123456789", "First_Name": "your first name", "Email":"first@gmail.com" } \], “triggger”:\[“workflow”,”approval”,”blueprint”\] }]
click here to view image (request and response via postman)
希望这会对您有所帮助。
答案 3 :(得分:0)
您必须将json文件发送到zoho api,并且一切正常。
$fields=["data"=> ['Last_Name'=>'Test John insert','Email'=>'testjhon@jhon.com']];
$fields = json_encode($fields);
答案 4 :(得分:0)
工作示例:
$fields = json_encode(array(
"data" => array([
"Company" => "abc",
"Last_Name" => "Tom",
"City" => "Egham"
],
[
"Company" => "abc",
"Last_Name" => "Jerry",
"City" => "Egham"
])
)
);
以这种方式发送标题:
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields),
sprintf('Authorization: Zoho-oauthtoken %s', $oauth)
);