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

Notion API创建页面添加多选标签失败,求正确实现示例

解决Notion API创建页面时添加多选标签的问题

问题场景

使用Notion API创建页面时,单选标签可正常添加,代码示例:

"City": {
    "select": {
        "name": "New York"
    }
}

但尝试添加多选标签时始终失败,我的错误代码:

"City": {
    "multi_select": {
           "options": [
            {
              "name": "New York", 
              "color": "red"
            },
            {
              "name": "Tbilisi",
              "color": "gray"
            }
          ]
    }
}

错误信息

收到400验证错误,核心提示为 body.properties.City.multi_select should be an array:

{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\nbody.properties.City.title should be defined, instead was `undefined`.\nbody.properties.City.rich_text should be defined, instead was `undefined`.\nbody.properties.City.number should be defined, instead was `undefined`.\nbody.properties.City.url should be defined, instead was `undefined`.\nbody.properties.City.select should be defined, instead was `undefined`.\nbody.properties.City.multi_select should be an array, instead was `{\"options\":[{\"name\":\"apple\",\"color\":\"red\"},{\"name\":\"Ora...`\nbody.properties.City.people should be defined, instead was `undefined`.\nbody.properties.City.email should be defined, instead was `undefined`.\nbody.properties.City.phone_number should be defined, instead was `undefined`.\nbody.properties.City.date should be defined, instead was `undefined`.\nbody.properties.City.checkbox should be defined, instead was `undefined`.\nbody.properties.City.relation should be defined, instead was `undefined`.\nbody.properties.City.files should be defined, instead was `undefined`.\nbody.properties.City.status should be defined, instead was `undefined`.\nbody.properties.Name.id should be defined, instead was `undefined`.\nbody.properties.Name.name should be defined, instead was `undefined`.\nbody.properties.Name.start should be defined, instead was `undefined`."}

我的完整请求Payload

newPageData = {
    "parent": { "database_id": 'some id' },
    "properties": {
        "Name": {
            "title": [
                {
                    "text": {
                        "content": "New page"
                    }
                }
            ]
        },
         "City": {
            "multi_select": {
                "options": [
                    {
                    "name": "New York", 
                    "color": "red"
                    },
                    {
                    "name": "Tbilisi",
                    "color": "gray"
                    }
                ]
            }
        },
        "Date": {
                "date": {
                    "start": "2023-02-06",
                    "end": None,
                }
            },
        "Link": {
                "url": "example.info"
            }
        }
    }

正确实现示例

问题出在multi_select的结构:它不需要嵌套options对象,直接传入标签数组即可。修正后的完整Payload:

newPageData = {
    "parent": { "database_id": 'some id' },
    "properties": {
        "Name": {
            "title": [
                {
                    "text": {
                        "content": "New page"
                    }
                }
            ]
        },
        "City": {
            "multi_select": [
                {
                    "name": "New York"
                },
                {
                    "name": "Tbilisi"
                }
            ]
        },
        "Date": {
            "date": {
                "start": "2023-02-06",
                "end": None
            }
        },
        "Link": {
            "url": "example.info"
        }
    }
}

补充说明

  • 如果需要新增标签并指定颜色,可在标签对象中添加color字段,比如{"name": "New York", "color": "red"};若数据库中已有同名标签,会直接使用现有标签的配置,无需指定颜色。
  • 注意语法细节:原代码中end: None后的逗号需要去掉(Python中最后一个键值对末尾不能加逗号)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 16:55:17