javascriptnode.jsnotion-apinotion

Creating multi-select tags via Notion API


I'm writing a programme to create a page under a Notion database using the API, but am having trouble getting the multi-select property to work

This is what I have written in properties { } (lines 67-76 of the code in my index.js in my repo)

  "multi-select": [
    { "name": tag1},
    { "name": tag2}
  ],

This is in an async function where tag1 and tag2 are string variables But when I run the code I get the following error:

'code: validation_error',  message: 'body failed validation. Fix one:\n' + .... {"object":"error", ...

(It's too long to paste but that's the gist. I screenshotted the full error here.)

The code works perfectly when I comment these lines out. I see no reason why this shouldn't work, so I suspect I have done something wrong in my set-up elsewhere, since I'm quite new to coding. The full repo is here - it's not long

Grateful for what I'm sure is probably a quick fix - thank you very much :)


Solution

  • There's a couple things going on with how you're trying to define the the multi select property:

    1. It should be multi_select not multi-select
    2. The body should be an object with an array of options, not just an array. I think you've copied some stuff from an API response which looks a little different.
     "Tags": {
        "multi_select": {
               "options": [
                {
                  "name": tag1, 
                  "color": "red"
                },
                {
                  "name": tag2,
                  "color": "gray"
                }
              ]},