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

使用PHP调用Monday.com API创建带列值条目报错求助

问题:调用Monday.com API创建条目时触发ColumnValueException错误

问题背景

使用PHP调用Monday.com API在看板上创建包含列值的新条目,但API返回格式错误异常。

我的代码

$query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item 
 (board_id:XXXXXXX, item_name:$myItemName, column_values:$columnVals) { id } }';
$vars = ['myItemName' => 'Test Veterinary Hospital', 
   'columnVals' => json_encode([
   'status' => ['label' => 'Agency'], 
   'text' => ['text' => 'Test Practice Management System'],
   'text7' => ['text' => 'https://example.com/'],
   'text6' => ['text' => 'Test Name'],
   'text37' => ['text' => 'Email'],
   'text1' => ['text' => 'test@example.com'],
   'text2' => ['text' => '555-555-5555'],
   'text3' => ['text' => '333-333-3333'],
   'text8' => ['text' => 'Test Address'],
   'text4' => ['text' => 'Yes'],
   'text87' => ['text' => 'No'],
   'date' => ['date' => '2023-08-27'],
   'date9' => ['date' => '2023-08-28'],
   'text17' => ['text' => '$1200'],
   'text71' => ['text' => 'Test Name'],
   'text86' => ['text' => 'Some notes here!']
 ])];

$data = @file_get_contents($apiUrl, false, stream_context_create([
    'http' => [
    'method' => 'POST',
    'header' => $headers,
    'content' => json_encode(['query' => $query, 'variables' => $vars]),
   ]
]));

$responseContent = json_decode($data, true);

echo json_encode($responseContent);

返回的错误信息

{"error_code":"ColumnValueException","status_code":200,"error_message":"invalid value, please check our API documentation for the correct data structure for this column. https://developer.monday.com/api-reference/docs/change-column-values","error_data":{"column_value":"{\"text\"=>\"Test Practice Management System\"}","column_type":"TextColumn"}}

对应列的结构信息

[2] => Array
      (
         [archived] => 
         [id] => text
         [pos] => 
         [settings_str] => {}
         [title] => Practice Management System
         [type] => text
         [width] => 297
       )

解决方案

问题出在Text类型列的格式错误:Monday.com的TextColumn列值仅接受纯字符串,不需要嵌套['text' => '内容']的结构,你之前的嵌套写法导致API识别为无效值。

修改后的代码中,所有Text类型列(id为text、text7、text6等)直接传入字符串即可,保留status、date等特殊类型列的原有嵌套结构:

$vars = ['myItemName' => 'Test Veterinary Hospital', 
   'columnVals' => json_encode([
   'status' => ['label' => 'Agency'], 
   'text' => 'Test Practice Management System',
   'text7' => 'https://example.com/',
   'text6' => 'Test Name',
   'text37' => 'Email',
   'text1' => 'test@example.com',
   'text2' => '555-555-5555',
   'text3' => '333-333-3333',
   'text8' => 'Test Address',
   'text4' => 'Yes',
   'text87' => 'No',
   'date' => ['date' => '2023-08-27'],
   'date9' => ['date' => '2023-08-28'],
   'text17' => '$1200',
   'text71' => 'Test Name',
   'text86' => 'Some notes here!'
 ])];

修改后重新调用API即可正常创建条目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 06:35:17