Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to create Children Blocks? #218

Unanswered
lbrpsoftware asked this question in Q&A
Discussion options

Hi,

I'm trying to create Children Blocks using the following code:

image

But I get this Error:

body failed validation. Fix one: body.heading_1 should be defined, instead was undefined. body.heading_2 should be defined, instead was undefined. body.heading_3 should be defined, instead was undefined. body.embed should be defined, instead was undefined. body.bookmark should be defined, instead was undefined. body.image should be defined, instead was undefined. body.video should be defined, instead was undefined. body.pdf should be defined, instead was undefined. body.file should be defined, instead was undefined. body.audio should be defined, instead was undefined. body.code should be defined, instead was undefined. body.equation should be defined, instead was undefined. body.divider should be defined, instead was undefined. body.breadcrumb should be defined, instead was undefined. body.table_of_contents should be defined, instead was undefined. body.link_to_page should be defined, instead was undefined. body.paragraph should be defined, instead was undefined. body.bulleted_list_item should be defined, instead was undefined. body.numbered_list_item should be defined, instead was undefined. body.quote should be defined, instead was undefined. body.to_do should be defined, instead was undefined. body.toggle should be defined, instead was undefined. body.template should be defined, instead was undefined. body.callout should be defined, instead was undefined. body.synced_block should be defined, instead was undefined. body.children should be not present, instead was [{"type":"bookmark","bookmark":{"url":"https://github.c....

I receive that same err when trying your example from the Tests.

What am I doing wrong here?
Thanks!

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

@lbrpsoftware The error is because the RichTextText type used sets the type property but when we Notion API do not expect type field when creating a block. I understand the error returned from the API is not very specific.

The solution to your problem is that you need to use the RichTextTextInput type instead which doesn't have type property. As of now we are reusing the model for Retrieve and Append API's and did not get time to separate them like we did for Update API. I will add issue in the milestone.

If you feel like contributing. I would be happy to accept the PR.

You must be logged in to vote
3 replies
Comment options

Comment options

I see now.

I'm short on time (as we all are ;), so presumed this functionality would be implemented without really having a look at your code, or understanding the API.

But your comment did point me to your other test class:
https://github.com/notion-dotnet/notion-sdk-net/blob/main/Test/Notion.UnitTests/DatabasesClientTests.cs
which works as expected, and will be sufficient for the things I need to do at this moment.

I'll surely consider contributing for this fine project in due time. But lets first get to know it a little better 👍

Thanks

Comment options

It's OK now! This is the start of the function to Create or Update a database item whenever an Issue over here changes. I'll leave this here:

 public async Task<Result<string>> ImportFromGitHubIssue(GitHubIssue issue, AppConfiguration appConfig)
 {
 string msg = "";
 try
 {
 _appConfig = appConfig;
 var client = NotionClientFactory.Create(new ClientOptions {
 AuthToken = appConfig.Notion
 });
 var databaseId = "1445ef62d7534a16a6d0c509a46d7ca1";
 // Update Database Title
 var updateDatabaseParameters = new DatabasesUpdateParameters();
 updateDatabaseParameters.Title = new List<RichTextBaseInput> {
 new RichTextTextInput {
 Text = new Text {
 Content = "GitHub Issues for " + issue.repository.name,
 Link = null
 }
 }
 };
 var database = await client.Databases.UpdateAsync(databaseId, updateDatabaseParameters);
 // Set GitHub Props
 var props = new Dictionary<string, PropertyValue>();
 props.Add("GitHub URL", new UrlPropertyValue() { Url = issue.issue.html_url });
 props.Add("Summary", new RichTextPropertyValue() { 
 RichText = new List<RichTextBase> {
 new RichTextTextInput {
 Text = new Text {
 Content = issue.issue.title,
 Link = null
 }
 }
 }, 
 });
 props.Add("Done", new CheckboxPropertyValue() { Checkbox = (issue.issue.state == "done") });
 props.Add("Created", new DatePropertyValue() { Date = new Date() { Start = issue.issue.created_at } });
 // Find Page in Database with GitHub URL
 var databasesQueryParams = new DatabasesQueryParameters {
 Filter = new TextFilter("GitHub URL", issue.issue.html_url)
 };
 var pagesPaginatedList = await client.Databases.QueryAsync(databaseId, databasesQueryParams);
 var pagesList = pagesPaginatedList.Results;
 if (pagesList.Count == 0) {
 // Add Page to Database
 var pagesCreateParameters = new PagesCreateParameters { Parent = new DatabaseParentInput() { DatabaseId = databaseId } };
 pagesCreateParameters.Properties = props;
 var page = await client.Pages.CreateAsync(pagesCreateParameters);
 } else {
 // Update Page in Database
 var pagesUpdateParameters = new PagesUpdateParameters();
 pagesUpdateParameters.Properties = props;
 var page = await client.Pages.UpdateAsync(pagesList[0].Id, pagesUpdateParameters);
 }
 }
 catch (Exception e)
 {
 msg = e.Message;
 }
 return await Result<string>.FailAsync(msg);
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /