首页 > 解决方案 > 在 PHP 中的 zoho api v2 中插入记录

问题描述

我想使用 api v2 在 zoho crm 中插入数据。首先制作一个数组,然后我编码 json .Request 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"}]}

标签: phpapicurlzoho

解决方案


工作示例:

$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)
);

推荐阅读