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

React+Axios调用monday.com GraphQL接口出现解析错误求助

问题原因与修复方案

你的错误根源在于GraphQL查询语句的字符串嵌套语法错误,以及变量传递方式不符合要求:

具体问题点

  1. 引号嵌套冲突:column_values: "{"value": "$column_values"}" 中外层双引号和内层双引号直接嵌套,导致GraphQL解析器无法正确识别字符串边界,这就是报错Parse error on ": " (STRING)的直接原因。
  2. 变量引用错误:你在字符串里直接写$column_values,但GraphQL变量的正确引用方式是在query中直接用$变量名,不需要包在字符串内部。
  3. column_values格式不符:monday.com的column_values要求接收JSON格式的字符串,你直接传递普通字符串不符合接口规范。

修复后的代码

const CreateItem = async () => {
    try {
      const response = await axios({
        url: endpoint,
        method: 'post',
        headers: headers,
        data: {
          // 修正query:直接引用$column_values变量,不再手动拼接JSON字符串
          "query": `mutation ($item_name: String!,$board_id: Int!,$group_id: String!,$column_values:String!) {
            create_item(
              item_name: $item_name,
              board_id: $board_id,
              group_id: $group_id,
              column_values: $column_values,
              create_labels_if_missing: true
            ) { id }
          }`,
          variables: {
            // 无需用String()包裹,直接传字符串即可
            item_name: "Testing Item",
            // 直接传数字,无需parseInt(如果是字符串形式的数字才需要转换)
            board_id: 3551570930,
            group_id: "topics",
            // 将需要的结构序列化为JSON字符串,符合column_values的格式要求
            column_values: JSON.stringify({ value: "Api Testing" })
          },
        }
      });

      if (response.data) {
        console.log(response.data);
      } else if (response.errors) {
        console.log(response.errors);
      }
    } catch (err) {
      console.log(err);
    }
  };

额外说明

  • 如果需要给column_values设置多个字段,只需扩展JSON对象即可,比如JSON.stringify({ value: "Api Testing", status: "Done" })。
  • 确保headers中包含monday.com要求的授权令牌(如Authorization: "YOUR_API_TOKEN"),这是请求成功的必要前提。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 01:31:08