jomei / notionapi

A Notion API SDK, written in Golang

Home Page:https://pkg.go.dev/github.com/jomei/notionapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unset date property

chapterjason opened this issue · comments

Currently, it isn't possible to unset a date property.
Making it a pointer works.

Date DateObject `json:"date"`

I've created a small workaround that works:

type EmptyDateProperty struct {
	ID   notionapi.ObjectID     `json:"id,omitempty"`
	Type notionapi.PropertyType `json:"type,omitempty"`
	Date *notionapi.DateObject  `json:"date"`
}

func (p EmptyDateProperty) GetType() notionapi.PropertyType {
	return p.Type
}

// [...]

updates["Completed At"] = &EmptyDateProperty{
    ID:   completedAtProperty.ID,
    Type: completedAtProperty.Type,
    Date: nil,
}

// [...]

Hi, @chapterjason !
Could you please provide an example use case where EmptyProperty is needed?

Hey @jomei

Sure,, I have a small task board with the following properties

  • Choice State with the values Blocked, In Progress and Done
  • Date Completed At

I've built a daemon which sets makest the following changes:

  • if state == "Done" && completedAt == nil set Completed At to now
  • if state != "Done" && completedAt != nil set Completed At to empty or clear as it is called in the UI of notion.

image