[英]Inserting record in zoho api v2 in PHP
I want to insert data in zoho crm using api v2.我想使用 api v2 在 zoho crm 中插入数据。 first make an array then i encoded json .Request url https://www.zohoapis.com/crm/v2/Contacts .
首先创建一个数组然后我编码 json .Request url https://www.zohoapis.com/crm/v2/Contacts 。 But i got this error.
但我得到了这个错误。
Code:代码:
$authtoken = ***********;
$fields={"data":["{\"Last_Name\":\"Test John insert\",\"Email\":\"testjhon@jhon.com\"}"]};
$zoho_url = "https://www.zohoapis.com/crm/v2/Contacts";
Error:错误:
{"data":[{"code":"INVALID_DATA","details":{"expected_data_type":"jsonobject","index":0},"message":"invalid data","status":"error"}]}
使用这个 json 数组:
$fields = "{\"data\":[{\"Last_Name\": \"Test\",\"First_Name\": \"TESTING\",\"Email\": \"demo@w3scloud.com\"}],\"trigger\":[\"approval\",\"workflow\"]}";
send this way :以这种方式发送:
[{ "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)单击此处查看图像(通过邮递员请求和响应)
hope this will help you.希望这会帮助你。
Working example:工作示例:
$fields = json_encode(
array(
"data" => array([
"Company" => "abc",
"Last_Name" => "Tom",
"City" => "Egham"
],
[
"Company" => "abc",
"Last_Name" => "Jerry",
"City" => "Egham"
])
)
);
Send headers this way :以这种方式发送标头:
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields),
sprintf('Authorization: Zoho-oauthtoken %s', $oauth)
);
I've noticed that Zoho seems to want an extra pair of brackets around the data.我注意到 Zoho 似乎想要在数据周围多加一对括号。 And you might try encoding the data array to a JSON-string before sending it to cURL.
您可以尝试将数据数组编码为 JSON 字符串,然后再将其发送到 cURL。
$fields = json_encode([
["data" => ["Last_Name" => "Test John insert","Email" => "testjhon@jhon.com"]],
]);
As @Ghost mentioned, you may also need to change the content-type.正如@Ghost 提到的,您可能还需要更改内容类型。 According to the PHP docs , passing an array to
CURLOPT_POSTFIELDS
will set the content-type to multipart/form-data
;根据PHP 文档,将数组传递给
CURLOPT_POSTFIELDS
会将内容类型设置为multipart/form-data
; what you probably want is application/json
.您可能想要的是
application/json
。
CURLOPT_HTTPHEADER => array(
"Authorization: ".$authtoken,
"Content-Type: application/json"
),
You must send the json file to zoho api, and all be works.:您必须将 json 文件发送到 zoho api,并且一切正常。:
$fields=["data"=> ['Last_Name'=>'Test John insert','Email'=>'testjhon@jhon.com']];
$fields = json_encode($fields);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.