notion-dotnet / notion-sdk-net

A Notion SDK for .Net
MIT License
181 stars 46 forks source link

Cannot Update Title of Page #346

Closed farukcan closed 1 year ago

farukcan commented 1 year ago

Doesnt work without error:

          var updateParameters = new PagesUpdateParameters{
            Properties = new Dictionary<string, PropertyValue>
                {
                    { "Name", blog.Name.ToTitlePropertyValue() }
                }
          };
          var page = await blogClient.Pages.UpdateAsync(duplicatedTemplateId, updateParameters);

Also doesnt work without error:

          var updateParameters = new PagesUpdateParameters{
            Properties = new Dictionary<string, PropertyValue>
                {
                    { "Title", blog.Name.ToTitlePropertyValue() }
                }
          };
          var page = await blogClient.Pages.UpdateAsync(duplicatedTemplateId, updateParameters);

Static function for fixing bad readibility

        public static TitlePropertyValue ToTitlePropertyValue(this string? text){
            return new TitlePropertyValue(){
                Title = new List<RichTextBase>(){
                    new RichTextText { Text = new Text { Content = text } }
                }
            };
        }
KoditkarVedant commented 1 year ago

@farukcan I believe the property key for title of page should be title lower-case. I tried to see if I could produce the issue but I was able to update the title of the page.

var pagesCreateParameters = PagesCreateParametersBuilder
    .Create(new ParentPageInput() { PageId = _databaseId })
    .AddProperty("title",
        new TitlePropertyValue
        {
            Title = new List<RichTextBase>
            {
                new RichTextTextInput { Text = new Text { Content = "Test Page Title" } }
            }
        }).Build();

var page = await _client.Pages.CreateAsync(pagesCreateParameters);

var updatePage = new PagesUpdateParameters()
{
    Properties = new Dictionary<string, PropertyValue>
    {
        {
            "title",
            new TitlePropertyValue()
            {
                Title = new List<RichTextBase>
                {
                    new RichTextText { Text = new Text() { Content = "Page Title Updated" } }
                }
            }
        }
    }
};

// Update
var updatedPage = await _client.Pages.UpdateAsync(page.Id, updatePage);

// Verify
var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync(
    new RetrievePropertyItemParameters
    {
        PageId = updatedPage.Id,
        PropertyId = updatedPage.Properties["title"].Id
    }
);

Assert.Equal("Page Title Updated", titleProperty.Results.First().As<TitlePropertyItem>().Title.PlainText);

// Clean Up
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true });

Note: Notion doesn't allow you to create title with custom key name it has to be title - it is case sensitive.

KoditkarVedant commented 1 year ago

stale - feel free to reopn