gpt4 book ai didi

json - Zoho CRM 使用 JSON/Coldfusion 插入记录

转载 作者:行者123 更新时间:2023-12-04 00:49:24 24 4
gpt4 key购买 nike

在最终找到 Zoho OAuth 身份验证后,我现在面临着在尝试插入新记录时调试错误代码的问题。

<cfsavecontent variable="JSONData">
{
"data": {
"Last_Name": "Smith",
"First_Name": "John",
"Email": "john@smith.com",
"Phone": "0123456789",
"Lead_Source": "PPC",
"Build_Cost_text": "50",
"Estimated_Sales_Value": "100",
"Stage_of_Build_Work": "Not Started",
"Work_Starting_Date_text": "01/06/2021",
"Number_of_Units": "1",
"Address_of_Development": "123 Any Street",
"Gross_floor_area_m2": "100",
"Development_Use": "Self Build",
"Please_share_any_additional_information": "Just testing stuff",
"Company": "Smith Widgets"
}
}
</cfsavecontent>


<cfhttp method="POST" url="https://www.zohoapis.com/crm/v2/Leads" result="zohopostresult">
<cfhttpparam type="header" name="Authorization" value="Zoho-oauthtoken #gettoken.access_token#">
<cfhttpparam type="header" name="content-type" value="application/json" />
<cfhttpparam type="body" value="#JSONData#" />
</cfhttp>

使用上述代码返回的错误是;

{"code":"INVALID_DATA","details":{"expected_data_type":"jsonarray","api_name":"data"},"message":"invalid data","status":"error"}

如果我使用 cfdump/deserializeJSON 查看“JSONData”变量,它的输出就很好。我一整天都在看这个,所以我很可能会错过一些直面我的东西。

最佳答案

为了理智,不要使用 <cfsavecontent> ,使用 <cfset>

<cfset payload = {
"data": {
"Last_Name": "Smith",
"First_Name": "John",
"Email": "john@smith.com",
"Phone": "0123456789",
"Lead_Source": "PPC",
"Build_Cost_text": "50",
"Estimated_Sales_Value": "100",
"Stage_of_Build_Work": "Not Started",
"Work_Starting_Date_text": "01/06/2021",
"Number_of_Units": "1",
"Address_of_Development": "123 Any Street",
"Gross_floor_area_m2": "100",
"Development_Use": "Self Build",
"Please_share_any_additional_information": "Just testing stuff",
"Company": "Smith Widgets"
}
}>

<cfdump var="#payload#">

<cfhttp method="POST" url="https://www.zohoapis.com/crm/v2/Leads" result="zohopostresult">
<cfhttpparam type="header" name="Authorization" value="Zoho-oauthtoken #gettoken.access_token#">
<cfhttpparam type="header" name="content-type" value="application/json" />
<cfhttpparam type="body" value="#SerializeJSON(payload)#" />
</cfhttp>

请注意,payload 将是一个结构体 - ColdFusion 支持结构体字面量语法,顺便说一句,它也接受 JSON 格式。

为了将数据作为 JSON 发送,您需要将其从结构序列化为字符串。这就是 SerializeJSON(payload) 的用途。

错误很明显。

"expected_data_type":"jsonarray"

所以你需要发送一个数组,而不是一个对象。我不知道 Zoho 的 API 定义,但我的猜测是要么

<cfset payload = {
"data": [{
...
}]
}>

<cfset payload = [{
"data": {
...
}
}]>

关于json - Zoho CRM 使用 JSON/Coldfusion 插入记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67792009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com