Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User object not being marshalled properly when trying to update a user in the People type DatabasePageProperty #54

Open
mikimichaeli opened this issue Mar 26, 2024 · 1 comment · May be fixed by #55

Comments

@mikimichaeli
Copy link

mikimichaeli commented Mar 26, 2024

Hi, great client!

When trying to update a People column in a database page (row), it seems that the User object is not being marshalled to the proper JSON object per the api.

Example usage of updating a page:

user := notion.User{BaseUser:  notion.BaseUser{ID: "<user-id>"}}
newPageProperties := notion.DatabasePageProperties{}
newPageProperties["Contributors"] = notion.DatabasePageProperty{People: []notion.User{user}}
res, err := n.Client.UpdatePage(ctx, "<page-id>", notion.UpdatePageParams{
		DatabasePageProperties: *newPageProperties,
})
if err != nil {
    fmt.Println(err)
}

The output error shows:

notion: failed to update page properties: body failed validation. Fix one:
body.properties.Contributors.people[0].type should be not present, instead was `""`.
body.properties.Contributors.people[0].name should be not present, instead was `""`.
body.properties.Contributors.people[0].avatar_url should be not present, instead was `""`.
body.properties.Contributors.people[0].person should be not present or an object, instead was `null`.
body.properties.Contributors.people[0].bot should be not present or an object, instead was `null`. (code: validation_error, status: 400)

from looking at the source code, I suspect the problem might be that the struct don't have an omitempty tag on their respective JSON representation. I'm happy to contribute an MR if needed

mikimichaeli added a commit to mikimichaeli/go-notion that referenced this issue Mar 26, 2024
@mikimichaeli mikimichaeli linked a pull request Mar 26, 2024 that will close this issue
@mikimichaeli
Copy link
Author

@dstotijn would appreciate your review 🙏🏼

@mikimichaeli mikimichaeli changed the title User object not being unmarshalled properly when trying to update a user in the People type DatabasePageProperty User object not being marshalled properly when trying to update a user in the People type DatabasePageProperty Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant