An API client for the Notion API implemented in Golang

notionapi

GitHub tag (latest SemVer) Go Reference Test

An API client for the Notion API implemented in Golang

Supported APIs

It supports all APIs for Notion API version 2021-05-13

  • Databases
  • Pages
  • Blocks
  • Users
  • Search

Installation

$ go get github.com/jomei/notionapi

Getting started

Follow Notion’s getting started guide to obtain an Integration Token.

Example

Make a new Client

import "github.com/jomei/notionapi"


client := notionapi.NewClient("your-integration-token")

Then, use client's methods to retrieve or update your content

page, err := client.Page.Get(context.Background(), "your-page-id")
if err != nil {
	// do something
}
Comments
  • Proposal: Defined Basic Block for embedding

    Proposal: Defined Basic Block for embedding

    This PR is in relation to #46. It implements the proposed changes.

    This commit adds a Basic Block type. The struct holds the common fields that Notion blocks have like ID, Creation data, etc. It implements the Block Interface. As a result, first, the embedding types will have access to all of the same fields, and second, will also implement the block interface.

  • Parent in PageCreateRequest is invalid

    Parent in PageCreateRequest is invalid

    parent is databaseParent or PageParent

    use a map format like

    {
        "parent": {
            "database_id": "abcd"
        }
    }
    

    Current in sdk is

    {
        "parent": {
            "type": "database_id",
            "database_id": "abcd"
        }
    }
    
  • Empty interfaces on some properties types.

    Empty interfaces on some properties types.

    While using the lib, I noticed that a bunch of properties have some fields typed with interface{}:

    • DateProperty.Date
    • PeopleProperty.People
    • CheckboxProperty.Checkbox
    • ...

    While technically, this doesn't prevent to use the API, it still shifts the work on the library user to handle those fields. Is there a particular reason motivating this choice?

    From my understanding so far, the API data structures for these fields are rather straightforward, thus it should be simple to handle those cases.

    I don't want to meddle with unwanted PRs, so I thought it'd be best to first discuss things here!

  • Added Property array to support unmarshalling

    Added Property array to support unmarshalling

    This is response to #51.

    This adds the PropertyArray type and defines an unmarshalling function for it. This will allow for the unmarshalling of Rollup arrays.

    This also moves some switch logic in parsePageProperties to a decodeProperty function which so it can be used in the unmarshalling of PropertyArray.

  • Added Blocks type for Unmarshalling

    Added Blocks type for Unmarshalling

    Currently there is a problem with unmarshalling into a Block interface, since the decodeBlock function is unexported. This is an issue when trying to use the Block type outside of the API, such as loading a Block from a JSON file. A Block itself cannot be defined to unmarshal into, as it is an interface and can't be a receiver, but a []Block can be, as done here.

    []Block cannot be unmarshalled into as it is an interface. This defines a Blocks type, which is just a []Block, and an UnmarshallJSON method so that a JSON string/byte slice can unmarshall into a []Block.

  • Block appendChildren Will return a error, but request is success

    Block appendChildren Will return a error, but request is success

    example code

    	key := "token token token"
    
    	client := notionapi.NewClient(notionapi.Token(key))
    
    	childrenvv := notionapi.ParagraphBlock{
    		Object: notionapi.ObjectTypeBlock,
    		Type:   notionapi.BlockTypeParagraph,
    		Paragraph: notionapi.Paragraph{
    			Text: []notionapi.RichText{
    				{
    					Type: notionapi.ObjectTypeText,
    					Text: notionapi.Text{
    						Content: "AAAAAA",
    					},
    					Annotations: &notionapi.Annotations{
    						Bold:          true,
    						Italic:        false,
    						Strikethrough: false,
    						Underline:     false,
    						Code:          false,
    						Color:         "",
    					},
    				},
    				{
    					Type: notionapi.ObjectTypeText,
    					Text: notionapi.Text{
    						Content: " BBBBB",
    					},
    					Annotations: &notionapi.Annotations{
    						Bold:          false,
    						Italic:        false,
    						Strikethrough: false,
    						Underline:     false,
    						Code:          false,
    						Color:         "",
    					},
    				},
    			},
    		},
    	}
    
    	req := notionapi.AppendBlockChildrenRequest{Children: []notionapi.Block{childrenvv}}
    
    	appendChildren, err := client.Block.AppendChildren(context.TODO(), "blockId(is a page)", &req)
    	if err != nil {
    		panic(err)
    	}
    
    	fmt.Println(appendChildren)
    

    get error : interface conversion: interface {} is nil, not string in github.com/jomei/[email protected]/block.go:537

  • fix RichText definition

    fix RichText definition

    According to the notion js definition for RichText, we have:

    type TextRequest = string
    
    type RichTextItemRequest =
      | {
          text: { content: string; link?: { url: TextRequest } | null }
          type?: "text"
    

    from: https://raw.githubusercontent.com/makenotion/notion-sdk-js/main/src/api-endpoints.ts

    but the definition in the current implementation was that the Link was a string instead of an object containing a URL.

    As an example, I have a page with:

            "text": {
              "content": "Gastbsy",
              "link": {
                "url": "https://www.gatsbyjs.com/"
              }
    

    This PR changes the type - and I was able to confirm that it is working for my notion page.

    PS: my vscode does some formatting automatically. It also caught a typo (omtiempty)

  • Query database: sort by page timestamps doesn't work

    Query database: sort by page timestamps doesn't work

    Thanks for developing this SDK within a few weeks after the public beta launch!

    Notion doc:

    Sorts are similar to the sorts provided in the Notion UI. Sorts operate on database properties or page timestamps and can be combined.

    It seems that Property Field of SortObject should be omitted in case of an empty value, to allow sort by page timestamps

    Otherwise notion API returns:

    {
        "object": "error",
        "status": 400,
        "code": "validation_error",
        "message": "Could not find sort property with name or id: "
    }
    
  • Supports update page's icon and cover

    Supports update page's icon and cover

    HiHi master, thanks for your SDK!

    The official API supports updating the icon and cover of the page. Could you update the SDK to support this function ?

  • Added some unsupported block types

    Added some unsupported block types

    This is for #45

    The following block types were added:

    • Breadcrumb
    • Column and Column List
    • Synced Block
    • Link to Page
    • Template
    • Equation
    • Link Preview Based on https://developers.notion.com/reference/block and testing.
  • Block's children not being decoded

    Block's children not being decoded

    The JSON decoder doesn't know how to parse the type []Block of children attributes.

    type ListItem struct {
    	Text     []RichText `json:"text"`
    	Children []Block    `json:"children,omitempty"`
    }
    ...
    type NumberedListItemBlock struct {
    	Object           ObjectType `json:"object"`
    	ID               BlockID    `json:"id,omitempty"`
    	Type             BlockType  `json:"type"`
    	CreatedTime      *time.Time `json:"created_time,omitempty"`
    	LastEditedTime   *time.Time `json:"last_edited_time,omitempty"`
    	HasChildren      bool       `json:"has_children,omitempty"`
    	NumberedListItem ListItem   `json:"numbered_list_item"`
    }
    

    This is due to Block beign an interface and JSON can't resolve dynamically the Block type.

    One way to solve this is creating a Block struct with the common attributes, decoding it first and then resolving the concrete type dynamically.

  • creating an inline database?

    creating an inline database?

    Thx for the cool package!

    Looks like the is_inline field was added in https://developers.notion.com/changelog/changes-for-june-6-june-20-2022 but I don't see suppport for in DatabaseCreateRequest. Of course I may just be missing it somewhere.

    I'd be willing to open a PR supporting is_inline on DB creation if there's interest.

  • Support for editing BasicBlock in every block

    Support for editing BasicBlock in every block

    Is it possible to add support for returning pointer to BasicBlock which is part of every block type? This would help editing the basic block field without needing to type cast Block interface to concrete block type object. Something similar to this

    type Block interface {
    	...
            ...
            ...
    	GetBasicBlock() *BasicBlock.  <-  New addition
    }
    ...
    ...
    ...
    func (b *BasicBlock) GetBasicBlock() *BasicBlock {
    	return b
    }
    

    If any client wants to edit something from BasicBlock which is common to all blocks, the client would always need to type cast the block interface to a particular block type and edit the BasicBlock info even when the client is not making any change specific to given block type.

  • Generating structs based on the typescript types from the official JS sdk

    Generating structs based on the typescript types from the official JS sdk

    After going back and forth on #9, it feels like making sure the API reference is properly implemented is a quite meticulous task that is quite error prone and may introduce vicious bugs that will be hard to track down.

    The official JS SDK has all the API types properly defined in Typescript, which could be used to generate those structs: https://github.com/makenotion/notion-sdk-js/blob/main/src/api-types.ts

    An example on how to achieve that can be found in gopls, which uses that approach to handle the structs that deals with the Language Server Protocol: https://github.com/golang/tools/tree/master/internal/lsp/protocol/typescript

    I may give it a try in the upcoming days, I'll post here if I do!

Go client for official Notion API.

notion notion is a Go client for the Notion API. Features The client supports all (non-deprecated) endpoints available in the Notion API, as of May 15

Dec 5, 2021
Unofficial SDK of official notion API in Go

notion-go A go client for the Notion API Description This aims to be an unofficial Go version of the official SDK which is written in JavaScript. Inst

May 12, 2022
Go written SDK for Notion.so API

go-notion Go written Notion SDK. Note: The Notion API is in beta phase Supported APIs It supports all APIs for Notion API (as for 2021-05-15). Blocks

Dec 10, 2021
Minimal go library for Notion's v1 API
Minimal go library for Notion's v1 API

go-notion (beta) go-notion is a minimal Go client library for Notion's v1 API. Check the usage or examples to see how to access Notion's v1 API. NB: N

Dec 7, 2022
A Go wrapper around the Notion API

go-notion A Go wrapper around the Notion API. | ⚠ This package is new and under active development. How to Use Install the package go get github.com/b

Nov 19, 2021
A cross platform desktop service that watches custom folders for file changes and updates the corresponding database in Notion.

A cross platform desktop service that watches custom folders for file changes and updates the corresponding database in Notion. Perfect for tracking reading lists

Mar 12, 2022
An app/container built in Go to automate a Twitter account using Notion

Notion Tweeter Notion Tweeter is a utility I built using Go to help automate scheduling my tweets using Notion as a backend. More documentation coming

Sep 26, 2022
Clusterpedia-client - clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Jan 7, 2022
Client-go - Clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Dec 5, 2022
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Kinesumer is a Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Jan 5, 2023
This repository will have code implemented for the 100 days of golang.

golang_100 This repository will have code implemented for the 100 days of golang. The resources I will use to do this 100 days golang programming are:

Jan 10, 2022
Nerftoken implemented in Golang
Nerftoken implemented in Golang

NerfToken - GolangEdition _ _ __ _______ _ | \ | | / _|__ __| | | | \| | ___

Sep 3, 2022
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

Feb 14, 2022
Firebase Cloud Messaging for application servers implemented using the Go programming language.

Firebase Cloud Notifications Client Firebase Cloud Messaging for application servers implemented using the Go programming language. It's designed for

Dec 17, 2022
Google Cloud Messaging for application servers implemented using the Go programming language.

gcm The Android SDK provides a nice convenience library (com.google.android.gcm.server) that greatly simplifies the interaction between Java-based app

Sep 27, 2022
Nutanix-client-go - Go client for the Nutanix Prism V3 API

nutanix-client-go This repository contains portions of the Nutanix API client code in nutanix/terraform-provider-nutanix. It has been extracted to red

Jan 6, 2022
Go-http-client: An enhanced http client for Golang
Go-http-client: An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Jan 7, 2023
Client for the cloud-iso-client

cloud-iso-client Client for the cloud-iso-client. Register an API token Before using this client library, you need to register an API token under your

Dec 6, 2021
Aoe4-client - Client library for aoe4 leaderboards etc

AOE4 Client Overview This is a go client used to query AOE4 data from either the

Jan 18, 2022