'Add event in notion Calendar

I want add item in my calendar on Notion. I manage to add item but without date. I don't know add date to my item.

Thanks

async function addItem(text) {
    try {
      const response = await notion.pages.create({
        parent: { database_id: databaseId },
        properties: {
            title: {
              type: 'title',
              title: [
                {
                  type: 'text',
                  text: {
                    content: 'Tomatoes',
                  },
                },
              ],
            },
        }
      })
      console.log(response)
      console.log("Success! Entry added.")
    } catch (error) {
      console.log("ERROR")
      console.error(error.body)
    }
  }
  
  addItem("Yurts in Big Sur, California")


Solution 1:[1]

If you want to add a date you need to make sure that the database you are adding to has that property for the same name. So if my database has a property called "Due Date" then I can do the following code to add this:

async function addItem(text, ddate) {
  try {
    const response = await notion.pages.create({
      parent: { database_id: database_id },
      properties: {
        title: { 
          title:[
            {
              "text": {
                "content": text
              }
            }
          ]
        },
        "Due Date": {
          date: {
            "start": ddate,
            "end": null
          }
        }  
      },
    })
    console.log(response)
    console.log("Success! Entry added.")
  } catch (error) {
    console.error(error.body)
  }
}


addItem("Test Add", "2022-03-29T11:00:00.000-04:00")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vignesh K.