Repository: jomei/notionapi
Pull request #112 (2022-09-14 10:51:51)

Added BlockID and Workspace to Parent object
In notion version 2022-06-28, Parent can point to 'block_id' as well.
Ref: https://developers.notion.com/reference/parent-object


Patch:
diff --git a/const.go b/const.go
index 3f1bbdc..f8827ff 100644
--- a/const.go
+++ b/const.go
@@ -180,6 +180,7 @@ const (
 	ParentTypeDatabaseID ParentType = "database_id"
 	ParentTypePageID     ParentType = "page_id"
 	ParentTypeWorkspace  ParentType = "workspace"
+	ParentTypeBlockID    ParentType = "block_id"
 )
 
 const (
diff --git a/page.go b/page.go
index bfe290f..528eef4 100644
--- a/page.go
+++ b/page.go
@@ -101,10 +101,13 @@ func (p *Page) GetObject() ObjectType {
 
 type ParentType string
 
+// Ref: https://developers.notion.com/reference/parent-object
 type Parent struct {
 	Type       ParentType `json:"type,omitempty"`
 	PageID     PageID     `json:"page_id,omitempty"`
 	DatabaseID DatabaseID `json:"database_id,omitempty"`
+	BlockID    BlockID    `json:"block_id,omitempty"`
+	Workspace  bool       `json:"workspace,omitempty"`
 }
 
 type PageCreateRequest struct {


Test patch:
diff --git a/database_test.go b/database_test.go
index 03f7e12..75765ca 100644
--- a/database_test.go
+++ b/database_test.go
@@ -278,6 +278,48 @@ func TestDatabaseClient(t *testing.T) {
 					},
 				},
 			},
+			{
+				name:       "returns created db 2",
+				filePath:   "testdata/database_create_2.json",
+				statusCode: http.StatusOK,
+				request: &notionapi.DatabaseCreateRequest{
+					Parent: notionapi.Parent{
+						Type:   notionapi.ParentTypePageID,
+						PageID: "some_id",
+					},
+					Title: []notionapi.RichText{
+						{
+							Type: notionapi.ObjectTypeText,
+							Text: &notionapi.Text{Content: "Grocery List"},
+						},
+					},
+					Properties: notionapi.PropertyConfigs{
+						"create": notionapi.TitlePropertyConfig{
+							Type: notionapi.PropertyConfigTypeTitle,
+						},
+					},
+				},
+				want: &notionapi.Database{
+					Object:         notionapi.ObjectTypeDatabase,
+					ID:             "some_id",
+					CreatedTime:    timestamp,
+					LastEditedTime: timestamp,
+					CreatedBy:      user,
+					LastEditedBy:   user,
+					Parent: notionapi.Parent{
+						Type:    "block_id",
+						BlockID: "a7744006-9233-4cd0-bf44-3a49de2c01b5",
+					},
+					Title: []notionapi.RichText{
+						{
+							Type:        notionapi.ObjectTypeText,
+							Text:        &notionapi.Text{Content: "Grocery List"},
+							PlainText:   "Grocery List",
+							Annotations: &notionapi.Annotations{Color: notionapi.ColorDefault},
+						},
+					},
+				},
+			},
 		}
 
 		for _, tt := range tests {
diff --git a/testdata/database_create_2.json b/testdata/database_create_2.json
new file mode 100644
index 0000000..1315ceb
--- /dev/null
+++ b/testdata/database_create_2.json
@@ -0,0 +1,47 @@
+{
+    "object": "database",
+    "id": "some_id",
+    "cover": {
+        "type": "external",
+        "external": {
+            "url": "https://website.domain/images/image.png"
+        }
+    },
+    "icon": {
+        "type": "emoji",
+        "emoji": "🎉"
+    },
+    "created_time": "2021-05-24T05:06:34.827Z",
+    "last_edited_time": "2021-05-24T05:06:34.827Z",
+    "created_by": {
+        "object": "user",
+        "id": "some_id"
+    },
+    "last_edited_by": {
+        "object": "user",
+        "id": "some_id"
+    },
+    "title": [
+        {
+            "type": "text",
+            "text": {
+                "content": "Grocery List",
+                "link": null
+            },
+            "annotations": {
+                "bold": false,
+                "italic": false,
+                "strikethrough": false,
+                "underline": false,
+                "code": false,
+                "color": "default"
+            },
+            "plain_text": "Grocery List",
+            "href": null
+        }
+    ],
+    "parent": {
+        "type": "block_id",
+        "block_id": "a7744006-9233-4cd0-bf44-3a49de2c01b5"
+    }
+}
\ No newline at end of file