php - 在 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"}]}
解决方案
工作示例:
$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)
);
推荐阅读
- vba - 有没有办法为日期设置自定义小时周期(不同于 24 小时)?
- arrays - 创建 vba 数组时出现类型不匹配错误
- c++ - 即使我已经声明了一个标识符,我在使用 c++ 的 Visual Studio 2019 中仍然收到未声明的标识符错误
- javascript - 在画布上绘制线条时的奇怪形状(js)
- java - UI 测试 Xamarin 应用程序:System.Exception:找不到 Java 开发工具包 (JDK)
- python - Colorama 输出随机的东西
- draw.io - draw.io 调整容器形状的展开/折叠 (+/-) 按钮
- log4j2 - 如何配置具有两个根级别的 log4j2?
- c# - 在 C# 中如何将属性名称和值列表转换为实例化的类对象
- javascript - 我怎样才能找到像“!”这样的特殊字符 或者 '?' 在 JavaScript 的对象数组中?