You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Deluge脚本发送GraphQL请求?Zoho CRM自定义函数调用报错

Zoho CRM自定义函数调用GraphQL API报错解决

问题场景

Postman中可正常运行的GraphQL查询参数:

{
  getLoanDetails(account:"399165061"){
   account
  }
}

Zoho CRM自定义函数原代码:

query = "{\"query\": \"{ getLoanDetails(account: \"399165061\") { account graceDays } }\", \"variables\": {} }";

header_data = Map();
header_data.put("Content-Type","application/json");
header_data.put("Authorization","Bearer key");
info query;
response = invokeurl
[
    url :"https://fapi.myfci.com/graphql"
    type :POST
    parameters:query 
    headers:header_data
    detailed:true
];
info response;

执行后报错:

{"responseText":{"errors":[{"message":"Expected a `String`-token, but found a `Integer`-token.","locations":[{"line":1,"column":39}],"extensions":{"code":"HC0011"}}]},"responseHeader":{"date":"Mon, 25 Mar 2024 09:54:23 GMT","transfer-encoding":"chunked","x-rate-limit-reset":"2024-03-25T09:54:38.8352528Z","content-type":"application/json; charset=utf-8","connection":"keep-alive","x-rate-limit-limit":"15s","x-rate-limit-remaining":"149","strict-transport-security":"max-age=15724800; includeSubDomains"},"responseCode":400}

错误原因

构造JSON字符串时,account参数值的双引号未正确转义,导致实际发送的请求中"399165061"变成了无引号的整数399165061,而API要求该参数为字符串类型,因此触发类型不匹配错误。

修复方案

方案1:正确转义内部双引号

将原query变量中的"399165061"改为\\"399165061\\",确保JSON解析后保留字符串引号:

query = "{\"query\": \"{ getLoanDetails(account: \\\"399165061\\\") { account graceDays } }\", \"variables\": {} }";

header_data = Map();
header_data.put("Content-Type","application/json");
header_data.put("Authorization","Bearer key");
info query;
response = invokeurl
[
    url :"https://fapi.myfci.com/graphql"
    type :POST
    parameters:query 
    headers:header_data
    detailed:true
];
info response;

方案2:使用Map构造请求体(推荐)

避免手动转义字符串,用Map构建JSON结构,再通过toString()转换为JSON字符串,更不易出错:

// 构建GraphQL查询内容
graphql_query = "{ getLoanDetails(account: \"399165061\") { account graceDays } }";

// 构建请求体Map
request_body = Map();
request_body.put("query", graphql_query);
request_body.put("variables", Map());

// 转换为JSON字符串
query = request_body.toString();

header_data = Map();
header_data.put("Content-Type","application/json");
header_data.put("Authorization","Bearer key");
info query;
response = invokeurl
[
    url :"https://fapi.myfci.com/graphql"
    type :POST
    parameters:query 
    headers:header_data
    detailed:true
];
info response;

内容的提问来源于stack exchange,提问作者Faraz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 07:40:32