如何在使用Notion API创建页面时添加新的或现有的多选标签?

huangapple go评论52阅读模式
英文:

How to add new or existing multi-select tags when creating a page in Notion API?

问题

我无法找出如何在Notion API中创建页面时添加多选标签。单选标签非常容易添加:

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

但是我的尝试添加多选标签最终失败:

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

这是我收到的错误消息:

{"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`."}

你有一个可以正常工作的示例吗?

这是完整的数据载荷:

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"
        }
    }
}
英文:

I can't figure out how to add multi-select tags when creating a page in Notion API. Single select tags are extremely easy to add:

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

But my attempts to add multi-select tags end up failing.

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

}

Here's the error I get

{"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`."}

Do you have a working example of how it should be done?

Here's the full 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"
            }
        }
    }

答案1

得分: 3

"When populating / updating a Multi-Select property, you don't need to include "options" or specify the option's colour so this should work -

"City": {
    "multi_select": [
        {
            "name": "New York"
        },
        {
            "name&quot: "Tbilisi"
        }
    ]
}

you should remove the first comma at the end of your list of options for the City property too -

    ]},

},
英文:

When populating / updating a Multi-Select property, you don't need to include "options" or specify the option's colour so this should work -

"City": {
    "multi_select": [
        {
            "name": "New York"
        },
        {
            "name": "Tbilisi"
        }
    ]
}

you should remove the first comma at the end of your list of options for the City property too -

    ]},

},

huangapple
  • 本文由 发表于 2023年2月6日 03:41:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定