An API client for the Notion API implemented in Golang

Overview

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
}
Issues
  • 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.

    opened by kertox662 7
  • 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"
        }
    }
    
    opened by Vaayne 6
  • 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!

    opened by jhchabran 6
  • 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.

    opened by kertox662 5
  • 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.

    opened by kertox662 4
  • 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

    opened by Kuri-su 4
  • 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)

    opened by pcarion 4
  • 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: "
    }
    
    opened by redaLaanait 4
  • 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 ?

    opened by SakuraDon99 3
  • 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.
    opened by kertox662 3
  • 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.

    opened by xzebra 3
  • Omit the unnecessary fields in toggle block

    Omit the unnecessary fields in toggle block

    The ToggleBlock specifies RichText and Text fields which are not documented in the Notion API. I suppose these were left from earlier versions.

    Practically, these fields should not be causing any errors as they're serialised only when they're present (i.e. omitempty). However, the RichText field misses the omitempty, causing error responses form Notion.

    Would be great if the unnecessary fields can be cleaned up - if that's too much work just adding an omitempty tag to ToggleBlock.RichText would do the job too.

    Ref. https://github.com/jomei/notionapi/blob/main/block.go#L352.

    PS, not sure how you manage contributions here, but given the right permissions I can open up a PR as well.

    Many thanks.

    opened by yoyomolinas 0
  • 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!

    opened by jhchabran 0
Releases(v1.8.5)
  • v1.8.5(Jun 13, 2022)

    What's Changed

    • Add missed properties to the File struct by @scottweitzner in https://github.com/jomei/notionapi/pull/90
    • Supported multidimensional compound and timestamp filters by @mcdoker18 in https://github.com/jomei/notionapi/pull/86
    • Move Caption field from CodeBlock into Code struct by @jomei in https://github.com/jomei/notionapi/pull/91
    Source code(tar.gz)
    Source code(zip)
  • v1.8.4(May 24, 2022)

    What's Changed

    • Enable to attach an cover when creating a page by @Kyya in https://github.com/jomei/notionapi/pull/85
    • Add background color and caption in code struct by @ariary in https://github.com/jomei/notionapi/pull/84
    Source code(tar.gz)
    Source code(zip)
  • v1.8.3(May 12, 2022)

    What's Changed

    • Add code block update by @ariary in https://github.com/jomei/notionapi/pull/78
    • Remove omitempty for DateObject on DateProperty by @chapterjason in https://github.com/jomei/notionapi/pull/79
    • Fix update ToDo block checkbox by @jomei in https://github.com/jomei/notionapi/pull/82
    Source code(tar.gz)
    Source code(zip)
  • v1.8.2(May 5, 2022)

    What's Changed

    • Deprecate filter.Text property and add filter.RichText instead by @jomei in https://github.com/jomei/notionapi/pull/74
    • Make DateProperty.DateObject nullable by @jomei in https://github.com/jomei/notionapi/pull/76
    Source code(tar.gz)
    Source code(zip)
  • v1.8.1(Apr 28, 2022)

    What's Changed

    • update text property to 2022-02-22 backwards incompatible changes by @nickysemenza in https://github.com/jomei/notionapi/pull/72
    • Add methods to Block interface to retrieve CreatedBy and LastEditedBy by @kertox662 in https://github.com/jomei/notionapi/pull/70
    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Apr 25, 2022)

    What's Changed

    • Add CreatedBy and LastEditedBy Fields to Structs by @kertox662 in https://github.com/jomei/notionapi/pull/67
    • Enable to attach an icon when creating a page by @Kyya in https://github.com/jomei/notionapi/pull/65
    • Update Default version to latest by @kertox662 in https://github.com/jomei/notionapi/pull/64
    • Deprecate 2022-02-22 backwards incompatible changes by @jomei in https://github.com/jomei/notionapi/pull/69
    Source code(tar.gz)
    Source code(zip)
  • v1.7.5(Mar 21, 2022)

  • v1.7.4(Feb 28, 2022)

  • v1.7.3(Jan 26, 2022)

  • v1.7.2(Jan 13, 2022)

  • v1.7.1(Dec 16, 2021)

    What's Changed

    • Added PropertyArray to support unmarshalling by @kertox662 in https://github.com/jomei/notionapi/pull/52
    • Added Blocks type for unmarshalling by @kertox662 in https://github.com/jomei/notionapi/pull/55
    Source code(tar.gz)
    Source code(zip)
  • v1.7.0(Nov 29, 2021)

    What's Changed

    • Proposal: Defined Basic Block for embedding by @kertox662 in https://github.com/jomei/notionapi/pull/47
    • Added some unsupported block types by @kertox662 in https://github.com/jomei/notionapi/pull/49
    • Added function to delete blocks by @yyewolf in https://github.com/jomei/notionapi/pull/50

    Full Changelog: https://github.com/jomei/notionapi/compare/v1.6.0...v1.7.0

    • All common Block fields were extracted to BasicBlock struct
    • New block types were added: EquationBlock, BreadcrumbBlock, ColumnBlock, ColumnListBlock, LinkPreviewBlock, LinkToPageBlock, TemplateBlock, SyncedBlock
    • Fix struct name typo: TableOfContentsBlock.TableOfContent -> TableOfContentsBlock.TableOfContents
    • Delete block function is now supported
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Nov 16, 2021)

    What's Changed

    • Change AppendBlockChildren response type from Block to AppendBlockChildrenResponse by @jomei in https://github.com/jomei/notionapi/pull/44
    Source code(tar.gz)
    Source code(zip)
  • v1.5.3(Oct 28, 2021)

    • added Cover attr to Page struct
    • added TableOfContents block
    • added Divider block
    • added Quote and Callout blocks
    • added Icon attr to the Page struct

    @pcarion and @xzebra ๐Ÿš€

    Source code(tar.gz)
    Source code(zip)
  • v1.5.2(Oct 13, 2021)

  • v1.5.1(Oct 6, 2021)

    • add Code block
    • handle pagination for Retrieve block children endpoint
    • add ChidDatabase block
    • change RichText.Link from string to object

    Thanks @xzebra and @pcarion ๐Ÿ”ฅ

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Sep 22, 2021)

  • v1.4.0(Sep 10, 2021)

  • v1.3.1(Aug 30, 2021)

  • v1.3.0(Aug 27, 2021)

  • v1.2.0(Aug 12, 2021)

    Fix #7

    Page and Database properties were separated into two sets of structs. Page now contains Properties and Database contains PropertiesConfig

    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(Aug 11, 2021)

  • v1.1.1(Aug 9, 2021)

  • v1.1.0(Aug 8, 2021)

    The Filter interface was removed. The DatabaseQueryRequest now provides two fields: a PropertyFilter for simple filters and a CompoundFilter for complex ones.

    PropertyFilter struct was reworked. The messy map[Condition]interface{} was replaced by a set of well-defined FilterCondition structs.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.5(Jul 31, 2021)

    The number property type in databases now supports additional currency options.

    The new options are:

    • "hong_kong_dollar"
    • "new_zealand_dollar"
    • "krona"
    • "norwegian_krone"
    • "mexican_peso"
    • "rand"
    • "new_taiwan_dollar"
    • "danish_krone"
    • "zloty"
    • "baht"
    • "forint"
    • "koruna"
    • "shekel"
    • "chilean_peso"
    • "philippine_peso"
    • "dirham"
    • "colombian_peso"
    • "riyal"
    • "ringgit"
    • "leu"
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Jul 19, 2021)

    • Fix URLProperty and FileProperty parsing.
    • Added SelectOptionProperty to distinguish page select property and database select property

    Thanks, @shayanh ๐Ÿ”ฅ

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Jul 6, 2021)

  • v1.0.1(Jun 18, 2021)

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

Krzysztof Kowalczyk 19 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

Pei-Ming Wu 11 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

Ketion.so 12 Dec 10, 2021
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

Ayomide Oyekanmi 17 Apr 15, 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

Brian Morrison II 1 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

Carl Kugblenu 2 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

Brian Morrison II 1 Jan 13, 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

Calvin Chen 4 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

clusterpedia.io 7 Jun 17, 2022
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.

๋‹น๊ทผ๋งˆ์ผ“ 64 Jul 15, 2022
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:

Vasileios Tsakalos 0 Jan 10, 2022
Nerftoken implemented in Golang

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

TNP IT Security 9 Jul 30, 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

Mad Devs 47 Jun 16, 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

Adriano Orioli 30 Nov 16, 2021
Client-server-golang-sqs - Client Server with SQS and golang

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

null 0 Feb 14, 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

Marvin Beckers 0 Jan 6, 2022
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

Furkan Bozdag 41 Jul 14, 2022
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

Virtomize 0 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

Mark Smith 0 Jan 18, 2022