Closed fmartingr closed 2 years ago
Managed to update it renaming the property to Title
and using the following code:
page, err := client.UpdatePage(ctx, "id", notion.UpdatePageParams{
DatabasePageProperties: ¬ion.DatabasePageProperties{
"Title": notion.DatabasePageProperty{
Type: notion.DBPropTypeTitle,
Title: []notion.RichText{
{
PlainText: name,
Text: ¬ion.Text{
Content: product.Name,
},
},
},
},
},
})
It didn't work having the property set as Name
using the following:
"Name": notion.DatabasePageProperty{
Type: notion.DBPropTypeTitle,
Title: []notion.RichText{
{
PlainText: name,
Name: "Name",
Text: ¬ion.Text{
Content: product.Name,
},
},
},
}
// nor using
"Title": notion.DatabasePageProperty{
Type: notion.DBPropTypeTitle,
Name: "Name",
The snippet from your first post should work (although you don't need to provide the PlainText
field; it's read-only and not used by the API when updating rich text objects). But perhaps product.Name
is not the same string value as name
? Thus, I'd advise to test with this snippet:
name := "New name"
page, err := client.UpdatePage(ctx, "<pageid>", notion.UpdatePageParams{
Title: []notion.RichText{
{
Text: ¬ion.Text{
Content: name,
},
},
},
})
Yeah sorry @dstotijn , I modified the code (adding name
) to provide an example but failed to replace product.Name
; in that case product.Name
is a string
and contains something, and it still didn't work. (Just tried it out again).
Strange; I can't reproduce the issue myself. When I test (with below test program) I'm able to update a page title, both pages with a workspace
parent type and with a database
parent type.
Could you maybe try testing with below program?
package main
import (
"context"
"errors"
"flag"
"fmt"
"log"
"os"
"github.com/davecgh/go-spew/spew"
"github.com/dstotijn/go-notion"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx := context.Background()
var pageID string
flag.StringVar(&pageID, "page-id", "", "Notion page ID. (Required)")
flag.Parse()
if pageID == "" {
flag.Usage()
return errors.New("flag `-page-id` must be set")
}
apiKey := os.Getenv("NOTION_API_KEY")
if apiKey == "" {
return errors.New(`Environment variable "NOTION_API_KEY" must be set.`)
}
client := notion.NewClient(apiKey)
params := notion.UpdatePageParams{
Title: []notion.RichText{
{
Text: ¬ion.Text{
Content: "Updated title",
},
},
},
}
updatedPage, err := client.UpdatePage(ctx, pageID, params)
if err != nil {
return fmt.Errorf("failed to update page: %w", err)
}
spew.Dump(updatedPage)
return nil
}
That code works well for be (using any name on the Title
database page property), after a few tests, it seems that providing DatabasePageProperties
along with the Update is causing to ignore the Title
attribute (I trimmed that from my first posts because I tought it was ireelevant). Am I unable to use the Title
if I provide my own DatabasePageProperties
?
I'm not sure if this is intended or not, but is a bit unintuitive for me.
(...) it seems that providing
DatabasePageProperties
along with the Update is causing to ignore theTitle
attribute
Ah, nice find!
I'm not sure if this is intended or not, but is a bit unintuitive for me.
That's not intended. I'll fix this sometime later this week.
Thank you for the fix @dstotijn ! Now I only need Notion to allow file uploads via API 😬
Hello, I'm trying to update a database entry title field (
Name
in my case) but I don't manage to do so. If I useName
on the properties it told me to use theTitle
, and using theTitle
does nothing (no errors). I can update other properties without issue.sample code:
I've tried several combinations, but nothing seems to being able to update the page title. I tried using "Title" as the field name (in case it was some JSON hardcoding) but that didn't work either.
Thanks for your work on this!