A Go client library for the Notion API.
Fork of jomei/notionapi with serialization bug fixes and support for Notion API version 2025-09-03 (multi-source databases).
- Serialization fixes: Added
omitemptytoStatusConfig,StatusPropertyConfig.ID,NumberFormat.Format, andSearchFilterfields that caused invalid JSON when empty - API v2025-09-03: Data source support (
DataSourceServicewith Get/Create/Update/Query/ListTemplates),DataSourceRefonDatabase,InitialDataSourceonDatabaseCreateRequest,DataSourceIDonParent, new object/parent type constants - Page move:
PageService.Moveto relocate pages to a new parent - Markdown read/write:
PageService.GetMarkdownandUpdateMarkdownfor reading/writing page content as markdown - Templates:
DataSourceService.ListTemplatesand template support onPageCreateRequest/PageUpdateRequest - Extended types:
is_locked,in_trashonPage;in_trash,is_inline,icon,coveronDatabaseUpdateRequest; additional metadata fields onDataSource - Module path:
github.com/rclod/notion-go
go get github.com/rclod/notion-goFirst, follow the Getting Started Guide to obtain an integration token.
import notionapi "github.com/rclod/notion-go"
client := notionapi.NewClient("your_integration_token")page, err := client.Page.Get(context.Background(), "your_page_id")
db, err := client.Database.Get(context.Background(), "your_database_id")In the latest API version, databases are containers with one or more data sources. Schema operations (properties) target data sources rather than databases directly.
// Get a data source (schema + properties)
ds, err := client.DataSource.Get(context.Background(), "your_data_source_id")
// Update data source schema
_, err = client.DataSource.Update(context.Background(), "your_data_source_id", ¬ionapi.DataSourceUpdateRequest{
Properties: notionapi.PropertyConfigs{
"Status": notionapi.SelectPropertyConfig{
Type: notionapi.PropertyConfigTypeSelect,
Select: notionapi.Select{
Options: []notionapi.Option{
{Name: "To Do", Color: "red"},
{Name: "Done", Color: "green"},
},
},
},
},
})
// Query pages in a data source
results, err := client.DataSource.Query(context.Background(), "your_data_source_id", ¬ionapi.DatabaseQueryRequest{
Filter: ¬ionapi.PropertyFilter{
Property: "Status",
Select: ¬ionapi.SelectFilterCondition{Equals: "Done"},
},
})ds, err := client.DataSource.Create(context.Background(), ¬ionapi.DataSourceCreateRequest{
Parent: notionapi.Parent{
Type: notionapi.ParentTypeDatabaseID,
DatabaseID: "your_database_id",
},
Properties: notionapi.PropertyConfigs{
"Name": notionapi.TitlePropertyConfig{Type: notionapi.PropertyConfigTypeTitle},
},
Title: []notionapi.RichText{
{Type: notionapi.RichTextTypeText, Text: ¬ionapi.Text{Content: "External Source"}},
},
})// List templates for a data source
templates, err := client.DataSource.ListTemplates(context.Background(), "your_data_source_id", nil)
// Create a page from a template
page, err := client.Page.Create(context.Background(), ¬ionapi.PageCreateRequest{
Parent: notionapi.Parent{
Type: notionapi.ParentTypeDataSourceID,
DataSourceID: "your_data_source_id",
},
Properties: notionapi.Properties{},
Template: ¬ionapi.PageTemplate{
Type: notionapi.TemplateTypeTemplateID,
TemplateID: templates.Templates[0].ID,
},
})page, err := client.Page.Move(context.Background(), "page_id", ¬ionapi.PageMoveRequest{
Parent: notionapi.Parent{
Type: notionapi.ParentTypePageID,
PageID: "new_parent_page_id",
},
})// Read page content as markdown
md, err := client.Page.GetMarkdown(context.Background(), "page_id")
fmt.Println(md.Markdown)
// Insert markdown content
updated, err := client.Page.UpdateMarkdown(context.Background(), "page_id", ¬ionapi.MarkdownUpdateRequest{
Type: "insert_content",
InsertContent: ¬ionapi.InsertContent{
Content: "## New Section\n\nHello world!\n",
},
})
// Replace a range of markdown content
updated, err = client.Page.UpdateMarkdown(context.Background(), "page_id", ¬ionapi.MarkdownUpdateRequest{
Type: "replace_content_range",
ReplaceContentRange: ¬ionapi.ReplaceContentRange{
Content: "## Updated Section\n",
ContentRange: "## Old Section\nOld content",
AllowDeletingContent: true,
},
})db, err := client.Database.Create(context.Background(), ¬ionapi.DatabaseCreateRequest{
Parent: notionapi.Parent{
Type: notionapi.ParentTypePageID,
PageID: "parent_page_id",
},
Title: []notionapi.RichText{
{Type: notionapi.RichTextTypeText, Text: ¬ionapi.Text{Content: "My Database"}},
},
InitialDataSource: ¬ionapi.InitialDataSource{
Properties: notionapi.PropertyConfigs{
"Name": notionapi.TitlePropertyConfig{Type: notionapi.PropertyConfigTypeTitle},
},
},
})