Zoho API V2更新记录 [英] Zoho API V2 Update Record

查看:132
本文介绍了Zoho API V2更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Zoho API版本2在Leads中进行简单的记录更新.我正在使用PHP和CURL,此调用的示例代码(更新记录中的单个字段)如下:-

I am trying to use the Zoho API Version 2 to do a simple record update in Leads. I am using PHP and CURL and my sample code for this call (to update a single field in the record) is as follows:-

$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/" . {valid record id here};

$headers = array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($fields),
    sprintf('Authorization: Zoho-oauthtoken %s', {valid auth token here})
);

$fields = json_encode([["data" => ["City" => "Egham"]]]);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 

$result = curl_exec($ch);

curl_close($ch); 

无论我如何格式化JSON,我总是会得到以下结果:

No matter how I format the JSON, I always get the following returned:

{"code":"INVALID_DATA","details": {"expected_data_type":"jsonobject"},"message":"body","status":"error"} 

这不是无效的身份验证令牌之类的问题,因为我已经成功地将PHP和CURL与Zoho API结合使用来读取数据,并且我成功解码了返回的JSON.

It is not a matter of invalid auth tokens etc because I have successfully used PHP and CURL with the Zoho API to read data and I decode the JSON returned successfully.

请帮助传递有效的JSON数据的人吗?

Please could somebody help with passing valid JSON data?

推荐答案

上面的代码像这样构造输入JSON [{"data":{"City":"Egham"}}].根据ZOHO CRM APIs( API帮助).

The above code constructs input JSON like this [{"data":{"City":"Egham"}}]. This JSON is not valid as per the ZOHO CRM APIs(API help).

应该是这样的{"data":[{"City":"Egham"}]}.

像这样更改代码:

$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/" . {valid record id here};

$fields = json_encode(array("data" => array(["City" => "Egham"])));

// *strlen must be called after defining the variable. So moved headers down to $fields*

$headers = array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($fields),
    sprintf('Authorization: Zoho-oauthtoken %s', {valid auth token here})
);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$result = curl_exec($ch);

curl_close($ch); 

这篇关于Zoho API V2更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆