在PHP中的zoho api v2中插入记录

问题描述 投票:0回答:5

我想使用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"}]}
php api curl zoho
5个回答
0
投票

使用这个json数组:

$fields = "{\"data\":[{\"Last_Name\": \"Test\",\"First_Name\": \"TESTING\",\"Email\": \"demo@w3scloud.com\"}],\"trigger\":[\"approval\",\"workflow\"]}";

0
投票

我注意到Zoho似乎想在数据周围增加一对括号。您可以尝试将数据数组编码为JSON字符串,然后再将其发送到cURL。

$fields = json_encode([
    ["data" => ["Last_Name" => "Test John insert","Email" => "testjhon@jhon.com"]],
]);

正如@Ghost所提到的,您可能还需要更改内容类型。根据PHP docs,将数组传递给CURLOPT_POSTFIELDS会将内容类型设置为multipart/form-data;你可能想要的是application/json

CURLOPT_HTTPHEADER => array(
    "Authorization: ".$authtoken,
    "Content-Type: application/json"
),

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)

希望这会帮助你。


0
投票

你必须将json文件发送到zoho api,并且所有工作都是:

  $fields=["data"=> ['Last_Name'=>'Test John insert','Email'=>'testjhon@jhon.com']];
  $fields = json_encode($fields);

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)
);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.