notion

package module
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2021 License: MIT Imports: 11 Imported by: 1

README

go-notion

tests Go Reference Go Report Card codecov

Go SDK for Notion Official API.

go get github.com/sorcererxw/go-notion

Overview

go-notion is the Golang binding for Notion official API. This package provides:

  • Easy-to-use and well-testing API wrappers.

  • Complete type definition.

You can easily and quickly build notion integrations with this package.

⚠️ Notion official API is still in public beta, it's hard to guarantee forward compatibility in the future. This package will be continuously updated according to the official documentation.

Getting Started

At the beginning, you should follow the official document to create your workspace and integrations.

package main

import (
	"context"

	"github.com/sorcererxw/go-notion"
)

func main() {
	client := notion.NewClient(notion.Settings{Token: "token"})

	database, err := client.RetrieveDatabase(context.Background(), "database_id")
}
Pagination
package main

func main() {
	var cursor string
	for {
		data, nextCursor, hasMore, err := client.ListAllUsers(context.Background(), 30, cursor)
		if err != nil {
			break
		}
		if !hasMore {
			break
		}
		cursor = nextCursor
	}
}
Error Handling

go-notion declares error codes . You can compare error code to confirm which error occurred.

package main

import (
	"context"
	"fmt"

	"github.com/sorcererxw/go-notion"
)

func main() {
	user, err := client.RetrieveUser(context.Background(), "user_id")
	if err, ok := notion.AsError(err); ok {
		switch err.Code {
		case notion.ErrCodeRateLimited:
			fmt.Println("rate limited")
		}
	}
}
Reverse Proxy

If you cannot access Notion server in your region(e.g. China) directly, you can use reverse proxy to solve the problem:

package main

import "github.com/sorcererxw/go-notion"

const proxyEndpoint = "https://1.1.1.1/notion"

func main() {
  client := notion.NewClient(notion.Settings{
      Token: "token",
      Endpoint: proxyEndpoint,
  })
}
OAuth
package main

import "net/http"

func main() {
  client := notion.NewOAuthClient("client_id", "client_secret", "redirect_uri")

  mux := http.NewServeMux()
  mux.HandleFunc("/oauth", func(w http.ResponseWriter, r *http.Request) {
    code := r.URL.Query().Get("code")
    token, _ := client.ExchangeAccessToken(r.Context(), code)
    
    // store token to db ...
    
    w.WriteHeader(http.StatusOK)
  })
}

License

go-notion is distributed under MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	// RetrieveDatabase retrieves a database.
	RetrieveDatabase(ctx context.Context, databaseID string) (*Database, error)
	// QueryDatabase queries a database.
	QueryDatabase(ctx context.Context, databaseID string, param QueryDatabaseParam) (results []*Page, nextCursor string, hasMore bool, err error)
	// ListDatabases lists databases.
	ListDatabases(ctx context.Context, pageSize int32, startCursor string) (results []*Database, nextCursor string, hasMore bool, err error)
	// RetrievePage retrieves a page.
	RetrievePage(ctx context.Context, pageID string) (*Page, error)
	// CreatePage creates a new page.
	CreatePage(ctx context.Context, parent Parent, properties map[string]*PropertyValue, children ...*Block) (*Page, error)
	// UpdatePageProperties updates pages' properties.
	UpdatePageProperties(ctx context.Context, pageID string, properties map[string]*PropertyValue) (*Page, error)
	// RetrieveBlockChildren retrieves child blocks of block.
	RetrieveBlockChildren(ctx context.Context, blockID string, pageSize int32, startCursor string) (results []*Block, nextCursor string, hasMore bool, err error)
	// AppendBlockChildren creates new child blocks.
	AppendBlockChildren(ctx context.Context, blockID string, children ...*Block) error
	// RetrieveUser retrieves user.
	RetrieveUser(ctx context.Context, userID string) (*User, error)
	// ListAllUsers lists all users.
	ListAllUsers(ctx context.Context, pageSize int32, startCursor string) (results []*User, nextCursor string, hasMore bool, err error)
	// Search searches objects.
	Search(ctx context.Context, param SearchParam) (results []*Object, nextCursor string, hasMore bool, err error)
}

API is declaration of Notion.so APIs.

func NewClient

func NewClient(settings Settings) API

NewClient creates a new API client.

type Annotation

type Annotation struct {
	// Whether the text is bolded.
	Bold bool `json:"bold,omitempty"`
	// Whether the text is italicized.
	Italic bool `json:"italic,omitempty"`
	// Whether the text is struck through.
	Strikethrough bool `json:"strikethrough,omitempty"`
	// Whether the text is underlined.
	Underline bool `json:"underline,omitempty"`
	// Whether the text is code style.
	Code bool `json:"code,omitempty"`
	// Color of the text.
	Color Color `json:"color,omitempty"`
}

Annotation is style information which applies to the whole rich text object.

type Block

type Block struct {
	Object           ObjectType `json:"object,omitempty"`
	ID               string     `json:"id,omitempty"`
	CreatedTime      time.Time  `json:"created_time,omitempty"`
	LastEditedTime   time.Time  `json:"last_edited_time,omitempty"`
	HasChildren      bool       `json:"has_children,omitempty"`
	Type             BlockType  `json:"type,omitempty"`
	Heading1         *Heading   `json:"heading_1,omitempty"`
	Heading2         *Heading   `json:"heading_2,omitempty"`
	Heading3         *Heading   `json:"heading_3,omitempty"`
	Paragraph        *Paragraph `json:"paragraph,omitempty"`
	BulletedListItem *ListItem  `json:"bulleted_list_item,omitempty"`
	NumberedListItem *ListItem  `json:"numbered_list_item,omitempty"`
	ToDo             *ToDo      `json:"to_do,omitempty"`
	Toggle           *Toggle    `json:"toggle,omitempty"`
	ChildPage        *ChildPage `json:"child_page,omitempty"`
}

Block object represents content within Notion.

func (*Block) MarshalJSON added in v0.2.3

func (b *Block) MarshalJSON() ([]byte, error)

MarshalJSON marshal Block to json and set Object to "block" automatically.

type BlockType

type BlockType string

BlockType is type of Block.

const (
	BlockParagraph        BlockType = "paragraph"
	BlockHeading1         BlockType = "heading_1"
	BlockHeading2         BlockType = "heading_2"
	BlockHeading3         BlockType = "heading_3"
	BlockBulletedListItem BlockType = "bulleted_list_item"
	BlockNumberedListItem BlockType = "numbered_list_item"
	BlockToDo             BlockType = "to_do"
	BlockToggle           BlockType = "toggle"
	BlockChildPage        BlockType = "child_page"
	BlockUnsupported      BlockType = "unsupported"
)

BlockType enums.

type CheckboxFilterCondition

type CheckboxFilterCondition struct {
	Equals       bool `json:"equals,omitempty"`
	DoesNotEqual bool `json:"does_not_equal,omitempty"`
}

CheckboxFilterCondition applies to database properties of type "checkbox".

type ChildPage

type ChildPage struct {
	Title string `json:"title,omitempty"`
}

ChildPage contains information of child page.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is implement of API.

func (*Client) AppendBlockChildren

func (c *Client) AppendBlockChildren(ctx context.Context, blockID string, children ...*Block) error

AppendBlockChildren implements API.AppendBlockChildren.

func (*Client) CreatePage

func (c *Client) CreatePage(ctx context.Context, parent Parent, properties map[string]*PropertyValue, children ...*Block) (*Page, error)

CreatePage implements API.CreatePage.

func (*Client) ListAllUsers

func (c *Client) ListAllUsers(ctx context.Context, pageSize int32, startCursor string) ([]*User, string, bool, error)

ListAllUsers implements API.ListAllUsers.

func (*Client) ListDatabases

func (c *Client) ListDatabases(ctx context.Context, pageSize int32, startCursor string) ([]*Database, string, bool, error)

ListDatabases implements API.ListDatabases.

func (*Client) QueryDatabase

func (c *Client) QueryDatabase(ctx context.Context, databaseID string, param QueryDatabaseParam) ([]*Page, string, bool, error)

QueryDatabase implements API.QueryDatabase.

func (*Client) RetrieveBlockChildren

func (c *Client) RetrieveBlockChildren(ctx context.Context, blockID string, pageSize int32, startCursor string) ([]*Block, string, bool, error)

RetrieveBlockChildren implements API.RetrieveBlockChildren.

func (*Client) RetrieveDatabase

func (c *Client) RetrieveDatabase(ctx context.Context, databaseID string) (*Database, error)

RetrieveDatabase implements API.RetrieveDatabase.

func (*Client) RetrievePage

func (c *Client) RetrievePage(ctx context.Context, pageID string) (*Page, error)

RetrievePage implements API.RetrievePage.

func (*Client) RetrieveUser

func (c *Client) RetrieveUser(ctx context.Context, userID string) (*User, error)

RetrieveUser implements API.RetrieveUser.

func (*Client) Search

func (c *Client) Search(ctx context.Context, param SearchParam) ([]*Object, string, bool, error)

Search implements API.Search.

func (*Client) UpdatePageProperties

func (c *Client) UpdatePageProperties(ctx context.Context, pageID string, properties map[string]*PropertyValue) (*Page, error)

UpdatePageProperties implements API.UpdatePageProperties.

type Color

type Color string

Color is color definition of Notion.

const (
	ColorDefault          Color = "default"
	ColorGray             Color = "gray"
	ColorBrown            Color = "brown"
	ColorOrange           Color = "orange"
	ColorYellow           Color = "yellow"
	ColorGreen            Color = "green"
	ColorBlue             Color = "blue"
	ColorPurple           Color = "purple"
	ColorPink             Color = "pink"
	ColorRed              Color = "red"
	ColorGrayBackground   Color = "gray_background"
	ColorBrownBackground  Color = "brown_background"
	ColorOrangeBackground Color = "orange_background"
	ColorYellowBackground Color = "yellow_background"
	ColorGreenBackground  Color = "green_background"
	ColorBlueBackground   Color = "blue_background"
	ColorPurpleBackground Color = "purple_background"
	ColorPinkBackground   Color = "pink_background"
	ColorRedBackground    Color = "red_background"
)

Color enums.

type Database

type Database struct {
	Object         ObjectType          `json:"object,omitempty"`
	ID             string              `json:"id,omitempty"`
	CreatedTime    time.Time           `json:"created_time,omitempty"`
	LastEditedTime time.Time           `json:"last_edited_time,omitempty"`
	Title          []*RichText         `json:"title,omitempty"`
	Properties     map[string]Property `json:"properties,omitempty"`
}

Database objects describe the property schema of a database in Notion. Page are the items (or children) in a database. Page property values must conform to the property objects laid out in the parent database object.

type Date

type Date struct {
	Start time.Time
	// If null, this property's date value is not a range.
	End *time.Time
}

Date represents a datetime or time range.

type DateFilterCondition

type DateFilterCondition struct {
	Equals     *time.Time `json:"equals,omitempty"`
	Before     *time.Time `json:"before,omitempty"`
	After      *time.Time `json:"after,omitempty"`
	OnOrBefore *time.Time `json:"on_or_before,omitempty"`
	OnOrAfter  *time.Time `json:"on_or_after,omitempty"`
	IsEmpty    bool       `json:"is_empty,omitempty"`
	IsNotEmpty bool       `json:"is_not_empty,omitempty"`
	PassWeek   *struct{}  `json:"pass_week,omitempty"`
	PastYear   *struct{}  `json:"past_year,omitempty"`
	NextWeek   *struct{}  `json:"next_week,omitempty"`
	NextMonth  *struct{}  `json:"next_month,omitempty"`
	NextYear   *struct{}  `json:"next_year,omitempty"`
}

DateFilterCondition applies to database properties of types "date", "created_time", and "last_edited_time".

type Equation

type Equation struct {
	// Expression The LaTeX string representing this inline equation.
	Expression string `json:"expression,omitempty"`
}

Equation .

type ErrCode

type ErrCode string

ErrCode is the "code" field in Notion error

const (
	// ErrCodeInvalidJSON The request body could not be decoded as JSON.
	ErrCodeInvalidJSON ErrCode = "invalid_json"
	// ErrCodeInvalidRequestURL The request URL is not valid.
	ErrCodeInvalidRequestURL ErrCode = "invalid_request_url"
	// ErrCodeInvalidRequest This request is not supported.
	ErrCodeInvalidRequest ErrCode = "invalid_request"
	// ErrCodeValidationError The request body does not match the schema for the expected parameters.
	// Check the "message" property for more details.
	ErrCodeValidationError ErrCode = "validation_error"
	// ErrCodeUnauthorized The bearer token is not valid.
	ErrCodeUnauthorized ErrCode = "unauthorized"
	// ErrCodeRestrictedResource Given the bearer token used, the client doesn't have permission to perform this operation.
	ErrCodeRestrictedResource ErrCode = "restricted_resource"
	// ErrCodeObjectNotFound Given the bearer token used, the resource does not exist.
	// This error can also indicate that the resource has not been shared with owner of the bearer token.
	ErrCodeObjectNotFound ErrCode = "object_not_found"
	// ErrCodeConflictError The transaction could not be completed, potentially due to a data collision.
	// Make sure the parameters are up to date and try again.
	ErrCodeConflictError ErrCode = "conflict_error"
	// ErrCodeRateLimited This request exceeds the number of requests allowed.
	// Slow down and try again.More details on rate limits
	ErrCodeRateLimited ErrCode = "rate_limited"
	// ErrCodeInternalServerError An unexpected error occurred.Reach out to Notion support.
	ErrCodeInternalServerError ErrCode = "internal_server_error"
	// ErrCodeServiceUnavailable Notion is unavailable. Try again later.
	// This can occur when the time to respond to a request takes longer than 60 seconds, the maximum request timeout.
	ErrCodeServiceUnavailable ErrCode = "service_unavailable"
)

type Error

type Error struct {
	Status  int     `json:"status,omitempty"`
	Code    ErrCode `json:"code,omitempty"`
	Message string  `json:"message,omitempty"`
}

Error is Notion error response body.

func AsError

func AsError(e error) (err *Error, ok bool)

AsError tries casting the basic error to notion error

func (*Error) Error

func (e *Error) Error() string

type File

type File struct {
	Name string `json:"name,omitempty"`
}

File reference is an object with an name property, with a string value corresponding to a filename of the original file upload (i.e. "Whole_Earth_Catalog.jpg").

type FilesFilterCondition

type FilesFilterCondition struct {
	IsEmpty    bool `json:"is_empty,omitempty"`
	IsNotEmpty bool `json:"is_not_empty,omitempty"`
}

FilesFilterCondition applies to database properties of type "files".

type Filter

type Filter struct {
	Property    string                      `json:"property,omitempty"`
	Text        *TextFilterCondition        `json:"text,omitempty"`
	Number      *NumberFilterCondition      `json:"number,omitempty"`
	Checkbox    *CheckboxFilterCondition    `json:"checkbox,omitempty"`
	Select      *SelectFilterCondition      `json:"select,omitempty"`
	MultiSelect *MultiSelectFilterCondition `json:"multi_select,omitempty"`
	Date        *DateFilterCondition        `json:"date,omitempty"`
	People      *PeopleFilterCondition      `json:"people,omitempty"`
	Files       *FilesFilterCondition       `json:"files,omitempty"`
	Relation    *RelationFilterCondition    `json:"relation,omitempty"`
	Formula     *FormulaFilterCondition     `json:"formula,omitempty"`
	// And is Compound filter.
	And []*Filter `json:"and,omitempty"`
	// Or is Compound filter.
	Or []*Filter `json:"or,omitempty"`
}

Filter is mix type of database query filter.

type FormulaFilterCondition

type FormulaFilterCondition struct {
	Text     *TextFilterCondition     `json:"text,omitempty"`
	Checkbox *CheckboxFilterCondition `json:"checkbox,omitempty"`
	Number   *NumberFilterCondition   `json:"number,omitempty"`
	Date     *DateFilterCondition     `json:"date,omitempty"`
}

FormulaFilterCondition applies to database properties of type "formula".

type FormulaValue

type FormulaValue struct {
	Type    FormulaValueType `json:"type,omitempty"`
	String  string           `json:"string,omitempty"`
	Number  float64          `json:"number,omitempty"`
	Boolean bool             `json:"boolean,omitempty"`
	Date    *Date            `json:"date,omitempty"`
}

FormulaValue represents the result of evaluating a formula described in the database's properties. These objects contain a type key and a key corresponding with the value of type.

type FormulaValueType

type FormulaValueType string

FormulaValueType is type of formula value.

const (
	FormulaValueString FormulaValueType = "string"
	FormulaValueNumber FormulaValueType = "number"
	FormulaValueBoolen FormulaValueType = "boolean"
	FormulaValueDate   FormulaValueType = "date"
)

FormulaValueType enums.

type Heading

type Heading struct {
	Text []*RichText `json:"text,omitempty"`
}

Heading is the common type of Heading1, Heading2, Heading3.

type Link struct {
	URL  string `json:"url,omitempty"`
	Type string `json:"type,omitempty"`
}

Link objects contain a type key whose value is always "url" and a url key whose value is a web address.

type List

type List struct {
	Object     ObjectType `json:"object,omitempty"`
	Results    Objects    `json:"results,omitempty"`
	NextCursor string     `json:"next_cursor,omitempty"`
	HasMore    bool       `json:"has_more,omitempty"`
}

List is Pagination response type.

type ListItem

type ListItem struct {
	Text     []*RichText `json:"text"`
	Children []*Block    `json:"children,omitempty"`
}

ListItem is the common type of BulletedListItem and NumberedListItem.

type Mention

type Mention struct {
	// Type of the inline mention.
	Type MentionType `json:"type,omitempty"`
	// User mentions contain a user object within the user property.
	User *User `json:"user,omitempty"`
	// Page mentions contain a page reference within the page property.
	// A page reference is an object with an id property, with a string value (UUIDv4) corresponding to a page ID.
	Page *ObjectReference `json:"page,omitempty"`
	// Database mentions contain a database reference within the database property.
	// A database reference is an object with an id property, with a string value (UUIDv4) corresponding to a database ID.
	Database *ObjectReference `json:"database,omitempty"`
	// Date mentions contain a date property value object within the date property.
	Date *Date `json:"date,omitempty"`
}

Mention objects represent an inline mention of a user, page, database, or date. In the app these are created by typing @ followed by the name of a user, page, database, or a date.

Mention objects contain a type key. In addition, mention objects contain a key corresponding with the value of type. The value is an object containing type-specific configuration. The type-specific configurations are described in the sections below.

type MentionType

type MentionType string

MentionType is type of Mention.

const (
	MentionUser     MentionType = "user"
	MentionPage     MentionType = "page"
	MentionDatabase MentionType = "database"
	MentionDate     MentionType = "date"
)

MentionType enums.

type MultiSelectFilterCondition

type MultiSelectFilterCondition struct {
	Contains       string `json:"contains,omitempty"`
	DoesNotContain string `json:"does_not_contain,omitempty"`
	IsEmpty        bool   `json:"is_empty,omitempty"`
	IsNotEmpty     bool   `json:"is_not_empty,omitempty"`
}

MultiSelectFilterCondition applies to database properties of type "multi_select".

type NumberFilterCondition

type NumberFilterCondition struct {
	Equals               float64 `json:"equals,omitempty"`
	DoesNotEqual         float64 `json:"does_not_equal,omitempty"`
	GreaterThan          float64 `json:"greater_than,omitempty"`
	LessThan             float64 `json:"less_than,omitempty"`
	GreaterThanOrEqualTo float64 `json:"greater_than_or_equal_to,omitempty"`
	LessThanOrEqualTo    float64 `json:"less_than_or_equal_to,omitempty"`
	IsEmpty              bool    `json:"is_empty,omitempty"`
	IsNotEmpty           bool    `json:"is_not_empty,omitempty"`
}

NumberFilterCondition applies to database properties of type "number".

type NumberFormat

type NumberFormat string

NumberFormat is format of number property value.

const (
	NumberFormatNumber           NumberFormat = "number"
	NumberFormatNumberWithCommas NumberFormat = "number_with_commas"
	NumberFormatPercent          NumberFormat = "percent"
	NumberFormatDollar           NumberFormat = "dollar"
	NumberFormatEuro             NumberFormat = "euro"
	NumberFormatPound            NumberFormat = "pound"
	NumberFormatYen              NumberFormat = "yen"
	NumberFormatRuble            NumberFormat = "ruble"
	NumberFormatRupee            NumberFormat = "rupee"
	NumberFormatWon              NumberFormat = "won"
	NumberFormatYuan             NumberFormat = "yuan"
)

NumberFormat enums.

type OAuthAccessToken

type OAuthAccessToken struct {
	AccessToken   string `json:"access_token,omitempty"`
	WorkspaceName string `json:"workspace_name,omitempty"`
	WorkspaceIcon string `json:"workspace_icon,omitempty"`
	BotID         string `json:"bot_id,omitempty"`
}

OAuthAccessToken is the response of OAuth token exchanging. You can use AccessToken as Client token to access normal Notion api.

type OAuthClient

type OAuthClient struct {
	// contains filtered or unexported fields
}

OAuthClient is client to exchange OAuth token.

func NewOAuthClient

func NewOAuthClient(clientID, clientSecret, redirectURI string) *OAuthClient

NewOAuthClient creates a OAuthClient.

func (*OAuthClient) ExchangeAccessToken

func (c *OAuthClient) ExchangeAccessToken(ctx context.Context, code string) (*OAuthAccessToken, error)

ExchangeAccessToken exchanges the auth code to api token.

type Object

type Object struct {
	Type ObjectType
	// contains filtered or unexported fields
}

Object is the mix type of Top-level resources.

func (*Object) Block

func (o *Object) Block() *Block

Block casts Object to Block

func (*Object) Database

func (o *Object) Database() *Database

Database casts Object to Database

func (*Object) List

func (o *Object) List() *List

List cast Object to List

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

MarshalJSON picks the value field for JSON marshalling.

func (*Object) Page

func (o *Object) Page() *Page

Page casts Object to Page

func (*Object) UnmarshalJSON

func (o *Object) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshalls bytes to the correct Object field according to "object" type field.

func (*Object) User

func (o *Object) User() *User

User casts Object to User

type ObjectReference

type ObjectReference struct {
	// Object may be empty in some cases.
	Object ObjectType `json:"object,omitempty"`
	ID     string     `json:"id,omitempty"`
}

ObjectReference is simple type of Object that just contains id and type.

type ObjectType

type ObjectType string

ObjectType is enum of Notion top level resource types.

const (
	ObjectList     ObjectType = "list"
	ObjectDatabase ObjectType = "database"
	ObjectPage     ObjectType = "page"
	ObjectUser     ObjectType = "user"
	ObjectBlock    ObjectType = "block"
)

ObjectType enums.

type Objects

type Objects []*Object

Objects is wrapper of Object list.

func (Objects) Blocks

func (os Objects) Blocks() []*Block

Blocks extracts valid blocks from objects.

func (Objects) Databases

func (os Objects) Databases() []*Database

Databases extracts valid databases from objects.

func (Objects) Pages

func (os Objects) Pages() []*Page

Pages extracts valid pages from objects.

func (Objects) Users

func (os Objects) Users() []*User

Users extracts valid users from objects.

type Page

type Page struct {
	Object         ObjectType               `json:"object,omitempty"`
	ID             string                   `json:"id,omitempty"`
	Title          string                   `json:"title,omitempty"`
	CreatedTime    time.Time                `json:"created_time"`
	LastEditedTime time.Time                `json:"last_edited_time"`
	Archived       bool                     `json:"archived,omitempty"`
	Properties     map[string]PropertyValue `json:"properties,omitempty"`
	Parent         Parent                   `json:"parent,omitempty"`
}

Page object contains the property values of a single Notion page. All pages have a parent. If the parent is a database, the property values conform to the schema laid out database's properties. Otherwise, the only property value is the title. Page content is available as blocks. The content can be read using retrieve block children and appended using append block children.

func (*Page) MarshalJSON added in v0.2.3

func (p *Page) MarshalJSON() ([]byte, error)

MarshalJSON marshal Page to json and set Object to "page" automatically.

type Paragraph

type Paragraph struct {
	Text     []*RichText `json:"text"`
	Children []*Block    `json:"children,omitempty"`
}

Paragraph is paragraph block.

type Parent

type Parent struct {
	Type       ParentType `json:"type,omitempty"`
	PageID     string     `json:"page_id,omitempty"`
	DatabaseID string     `json:"database_id,omitempty"`
	Workspace  bool       `json:"workspace,omitempty"`
}

Parent represents the Page parent.

func NewDatabaseParent

func NewDatabaseParent(databaseID string) Parent

NewDatabaseParent creates a database parent.

func NewPageParent

func NewPageParent(pageID string) Parent

NewPageParent creates a page parent.

func NewWorkspaceParent

func NewWorkspaceParent() Parent

NewWorkspaceParent creates a workspace parent.

type ParentType

type ParentType string

ParentType is type of Parent.

const (
	ParentDatabase  ParentType = "database_id"
	ParentPage      ParentType = "page_id"
	ParentWorkspace ParentType = "workspace"
)

ParentType enums.

type PeopleFilterCondition

type PeopleFilterCondition struct {
	Contains       string `json:"contains,omitempty"`
	DoesNotContain string `json:"does_not_contain,omitempty"`
	IsEmpty        string `json:"is_empty,omitempty"`
	IsNotEmpty     string `json:"is_not_empty,omitempty"`
}

PeopleFilterCondition applies to database properties of types "date", "created_by", and "last_edited_by".

type Property added in v0.2.3

type Property struct {
	ID       string       `json:"id,omitempty"`
	Type     PropertyType `json:"type,omitempty"`
	Title    *struct{}    `json:"title,omitempty"`
	RichText *struct{}    `json:"rich_text,omitempty"`
	Number   *struct {
		Format NumberFormat `json:"format,omitempty"`
	} `json:"number,omitempty"`
	Select *struct {
		Options []*SelectOption `json:"options,omitempty"`
	} `json:"select,omitempty"`
	MultiSelect *struct {
		Options []*SelectOption `json:"options,omitempty"`
	} `json:"multi_select,omitempty"`
	Checkbox    *struct{} `json:"checkbox,omitempty"`
	URL         *struct{} `json:"url,omitempty"`
	Email       *struct{} `json:"email,omitempty"`
	PhoneNumber *struct{} `json:"phone_number,omitempty"`
	Formula     *struct {
		Expression string `json:"expression,omitempty"`
	} `json:"formula,omitempty"`
	Relation *struct {
		DatabaseID         string `json:"database_id,omitempty"`
		SyncedPropertyName string `json:"synced_property_name,omitempty"`
		SyncedPropertyID   string `json:"synced_property_id,omitempty"`
	} `json:"relation,omitempty"`
	Rollup *struct {
		RelationPropertyName string `json:"relation_property_name,omitempty"`
		RelationPropertyID   string `json:"relation_property_id,omitempty"`
		RollupPropertyName   string `json:"rollup_property_name,omitempty"`
		RollupPropertyID     string `json:"rollup_property_id,omitempty"`
		Function             string `json:"function,omitempty"`
	} `json:"rollup,omitempty"`
	People         *struct{} `json:"people,omitempty"`
	Date           *struct{} `json:"date,omitempty"`
	File           *struct{} `json:"files,omitempty"`
	CreatedTime    *struct{} `json:"created_time,omitempty"`
	CreatedBy      *struct{} `json:"created_by,omitempty"`
	LastEditedTime *struct{} `json:"last_edited_time,omitempty"`
	LastEditedBy   *struct{} `json:"last_edited_by,omitempty"`
}

Property is mix type of database property.

type PropertyType

type PropertyType string

PropertyType is type of database Property.

const (
	PropertyTitle          PropertyType = "title"
	PropertyRichText       PropertyType = "rich_text"
	PropertyNumber         PropertyType = "number"
	PropertySelect         PropertyType = "select"
	PropertyMultiSelect    PropertyType = "multi_select"
	PropertyDate           PropertyType = "date"
	PropertyPeople         PropertyType = "people"
	PropertyFile           PropertyType = "file"
	PropertyCheckbox       PropertyType = "checkbox"
	PropertyURL            PropertyType = "url"
	PropertyEmail          PropertyType = "email"
	PropertyPhoneNumber    PropertyType = "phone_number"
	PropertyFormula        PropertyType = "formula"
	PropertyRelation       PropertyType = "relation"
	PropertyRollup         PropertyType = "rollup"
	PropertyCreatedTime    PropertyType = "created_time"
	PropertyCreatedBy      PropertyType = "created_by"
	PropertyLastEditedTime PropertyType = "last_edited_time"
	PropertyLastEditedBy   PropertyType = "last_edited_by"
)

PropertyType enums.

type PropertyValue added in v0.2.3

type PropertyValue struct {
	ID          string          `json:"id,omitempty"`
	Type        PropertyType    `json:"type,omitempty"`
	Title       []*RichText     `json:"title,omitempty"`
	RichText    []*RichText     `json:"rich_text,omitempty"`
	Number      float64         `json:"number,omitempty"`
	Select      *SelectOption   `json:"select,omitempty"`
	MultiSelect []*SelectOption `json:"multi_select,omitempty"`
	Date        *Date           `json:"date,omitempty"`
	Formula     *FormulaValue   `json:"formula,omitempty"`
	// Relation is an array of page references.
	Relation []*ObjectReference `json:"relation,omitempty"`
	Rollup   *RollupValue       `json:"rollup,omitempty"`
	// People is an array of user objects.
	People []*User `json:"people,omitempty"`
	// Files is an array of file references.
	Files    []*File `json:"files,omitempty"`
	Checkbox bool    `json:"checkbox,omitempty"`
	// URL describes a web address (i.e. "http://worrydream.com/EarlyHistoryOfSmalltalk/").
	URL string `json:"url,omitempty"`
	// Email describes an email address (i.e. "hello@example.org").
	Email string `json:"email,omitempty"`
	// PhoneNumber describes a phone number. No structure is enforced.
	PhoneNumber string `json:"phone_number,omitempty"`
	// CreatedBy describes the user who created this page.
	CreatedBy *User `json:"created_by,omitempty"`
	// LastEditedBy describes the user who last updated this page.
	LastEditedBy *User `json:"last_edited_by,omitempty"`
	// CreatedTime contains the date and time when this page was created.
	CreatedTime *time.Time `json:"created_time,omitempty"`
	// LastEditedTime contains the date and time when this page was last updated.
	LastEditedTime *time.Time `json:"last_edited_time,omitempty"`
}

PropertyValue is the property value of Page. It must contain a key corresponding with the value of type. The value is an object containing type-specific data.

func NewCheckboxPropertyValue added in v0.2.3

func NewCheckboxPropertyValue(check bool) *PropertyValue

NewCheckboxPropertyValue creates a CheckboxPropertyValue.

func NewDatePropertyValue added in v0.2.3

func NewDatePropertyValue(date *Date) *PropertyValue

NewDatePropertyValue creates a DatePropertyValue.

func NewEmailPropertyValue added in v0.2.3

func NewEmailPropertyValue(email string) *PropertyValue

NewEmailPropertyValue creates a EmailPropertyValue.

func NewFilesPropertyValue added in v0.2.3

func NewFilesPropertyValue(files ...*File) *PropertyValue

NewFilesPropertyValue creates a FilesPropertyValue.

func NewMultiSelectPropertyValue added in v0.2.3

func NewMultiSelectPropertyValue(options ...*SelectOption) *PropertyValue

NewMultiSelectPropertyValue creates a MultiSelectPropertyValue.

func NewNumberPropertyValue added in v0.2.3

func NewNumberPropertyValue(number float64) *PropertyValue

NewNumberPropertyValue creates a NumberPropertyValue.

func NewPeoplePropertyValue added in v0.2.3

func NewPeoplePropertyValue(people ...*User) *PropertyValue

NewPeoplePropertyValue creates a PeoplePropertyValue.

func NewPhoneNumberPropertyValue added in v0.2.4

func NewPhoneNumberPropertyValue(phoneNumber string) *PropertyValue

NewPhoneNumberPropertyValue creates a PhonePropertyValue.

func NewRelationPropertyValue added in v0.2.3

func NewRelationPropertyValue(relation ...*ObjectReference) *PropertyValue

NewRelationPropertyValue creates a RelationPropertyValue.

func NewRichTextPropertyValue added in v0.2.3

func NewRichTextPropertyValue(texts ...*RichText) *PropertyValue

NewRichTextPropertyValue creates a RichTextPropertyValue.

func NewSelectPropertyValue added in v0.2.3

func NewSelectPropertyValue(option *SelectOption) *PropertyValue

NewSelectPropertyValue creates a SelectPropertyValue.

func NewTitlePropertyValue added in v0.2.3

func NewTitlePropertyValue(texts ...*RichText) *PropertyValue

NewTitlePropertyValue creates a TitlePropertyValue.

func NewURLPropertyValue added in v0.2.3

func NewURLPropertyValue(url string) *PropertyValue

NewURLPropertyValue creates a URLPropertyValue.

type QueryDatabaseParam

type QueryDatabaseParam struct {
	Filter      *Filter `json:"filter,omitempty"`
	Sorts       []*Sort `json:"sorts,omitempty"`
	StartCursor string  `json:"start_cursor,omitempty"`
	PageSize    int32   `json:"page_size,omitempty"`
}

QueryDatabaseParam is the param of QueryDatabase.

type RelationFilterCondition

type RelationFilterCondition struct {
	Contains       string `json:"contains,omitempty"`
	DoesNotContain string `json:"does_not_contain,omitempty"`
	IsEmpty        bool   `json:"is_empty,omitempty"`
	IsNotEmpty     bool   `json:"is_not_empty,omitempty"`
}

RelationFilterCondition applies to database properties of type "relation".

type RichText

type RichText struct {
	// The plain text without annotations.
	PlainText string `json:"plain_text,omitempty"`
	// The URL of any link or internal Notion mention in this text, if any.
	Href string `json:"href,omitempty"`
	// All annotations that apply to this rich text.
	// Annotations include colors and bold/italics/underline/strikethrough.
	Annotations Annotation `json:"annotations"`
	// Type of this rich text object.
	Type     RichTextType `json:"type,omitempty"`
	Text     *Text        `json:"text,omitempty"`
	Mention  *Mention     `json:"mention,omitempty"`
	Equation *Equation    `json:"equation,omitempty"`
}

RichText objects contain data for displaying formatted text, mentions, and equations. RichText object also contains annotations for style information. Arrays of rich text objects are used within property objects and property value objects to create what a user sees as a single text value in Notion.

type RichTextType

type RichTextType string

RichTextType is type of RichText.

const (
	RichTextText     RichTextType = "text"
	RichTextMention  RichTextType = "mention"
	RichTextEquation RichTextType = "equation"
)

RichTextType enums.

type RollupValue

type RollupValue struct {
	Type   RollupValueType `json:"type,omitempty"`
	Number float64         `json:"number,omitempty"`
	Date   *Date           `json:"date,omitempty"`
	// The element is exactly like property value object, but without the "id" key.
	Array []*PropertyValue `json:"array,omitempty"`
}

RollupValue represent the result of evaluating a rollup described in the database's properties. These objects contain a type key and a key corresponding with the value of type. The value is an object containing type-specific data.

type RollupValueType

type RollupValueType string

RollupValueType is type of rollup value.

const (
	RollupValueString RollupValueType = "string"
	RolluoValueDate   RollupValueType = "date"
	RolluoValueArray  RollupValueType = "array"
)

RollupValueType enums.

type SearchFilter

type SearchFilter struct {
	// The value of the property to filter the results by.
	// Possible values for object type include page or database.
	// Limitation: Currently the only filter allowed is object which will filter by type of object (either page or database)
	Value string `json:"value,omitempty"`
	// The name of the property to filter by. Currently the only property you can filter by is the object type.
	// Possible values include object.
	// Limitation: Currently the only filter allowed is object which will filter by type of object (either page or database)
	Property string `json:"property,omitempty"`
}

SearchFilter when supplied, filters the results based on the provided criteria.

type SearchParam

type SearchParam struct {
	// The query parameter matches against the page titles.
	// When supplied, limits which pages are returned by comparing the query to the page title.
	// If the query parameter is not provided, the response will contain all pages (and child pages) in the results.
	Query string `json:"query,omitempty"`
	// When supplied, sorts the results based on the provided criteria.
	// Limitation: Currently only a single sort is allowed and is limited to last_edited_time.
	Sort *Sort `json:"sort,omitempty"`
	// The filter parameter can be used to query specifically for only pages or only databases.
	// When supplied, filters the results based on the provided criteria.
	Filter      *SearchFilter `json:"filter,omitempty"`
	StartCursor string        `json:"start_cursor,omitempty"`
	PageSize    int32         `json:"page_size,omitempty"`
}

SearchParam is param of Search.

type SelectFilterCondition

type SelectFilterCondition struct {
	Equals       string `json:"equals,omitempty"`
	DoesNotEqual string `json:"does_not_equal,omitempty"`
	IsEmpty      bool   `json:"is_empty,omitempty"`
	IsNotEmpty   bool   `json:"is_not_empty,omitempty"`
}

SelectFilterCondition applies to database properties of type "select".

type SelectOption

type SelectOption struct {
	Name  string `json:"name,omitempty"`
	ID    string `json:"id,omitempty"`
	Color Color  `json:"color,omitempty"`
}

SelectOption is the option value of single selector and multi selector.

type Settings

type Settings struct {
	Token      string
	Endpoint   string
	HTTPClient *http.Client
}

Settings is configuration of Client.

type Sort

type Sort struct {
	// The direction to sort.
	Direction SortDirection `json:"direction,omitempty"`
	// The name of the timestamp to sort against. Possible values include "created_time" and "last_edited_time".
	Timestamp string `json:"timestamp,omitempty"`
	// The name of the property to sort against.
	Property string `json:"property,omitempty"`
}

Sort sorts the results based on the provided criteria.

func SortByCreatedTime

func SortByCreatedTime(direction SortDirection) *Sort

SortByCreatedTime creates Sort to sort database by "created_time".

func SortByLastEditedTime

func SortByLastEditedTime(direction SortDirection) *Sort

SortByLastEditedTime creates Sort to sort database by "last_edited_time".

func SortByProperty

func SortByProperty(property string, direction SortDirection) *Sort

SortByProperty creates Sort to sort database by specified property.

type SortDirection

type SortDirection string

SortDirection query result order.

const (
	DirectionAscending  SortDirection = "ascending"
	DirectionDescending SortDirection = "descending"
)

SortDirection enums.

type Text

type Text struct {
	// Text content. This field contains the actual content of your text and is probably the field you'll use most often.
	Content string `json:"content,omitempty"`
	// Any inline link in this text.
	Link *Link `json:"link,omitempty"`
}

Text is the content of rich text.

type TextFilterCondition

type TextFilterCondition struct {
	Equals         string `json:"equals,omitempty"`
	DoesNotEqual   string `json:"does_not_equal,omitempty"`
	Contains       string `json:"contains,omitempty"`
	DoesNotContain string `json:"does_not_contain,omitempty"`
	StartsWith     string `json:"starts_with,omitempty"`
	EndsWith       string `json:"ends_with,omitempty"`
	IsEmpty        bool   `json:"is_empty,omitempty"`
	IsNotEmpty     bool   `json:"is_not_empty,omitempty"`
}

TextFilterCondition applies to database properties of types "title", "rich_text", "url", "email", and "phone".

type ToDo added in v0.2.4

type ToDo struct {
	Text     []*RichText `json:"text,omitempty"`
	Children []*Block    `json:"children,omitempty"`
	Checked  bool        `json:"checked,omitempty"`
}

ToDo is todo item.

type Toggle

type Toggle struct {
	Text     []*RichText `json:"text"`
	Children []*Block    `json:"children,omitempty"`
}

Toggle is toggle item.

type User

type User struct {
	// Always "user"
	Object ObjectType `json:"object,omitempty"`
	ID     string     `json:"id,omitempty"`
	Type   UserType   `json:"type,omitempty"`
	// Properties only present for non-bot users.
	Person *struct {
		Email string `json:"email,omitempty"`
	} `json:"person,omitempty"`
	// Properties only present for bot users.
	Bot       *struct{} `json:"bot,omitempty"`
	Name      string    `json:"name,omitempty"`
	AvatarURL string    `json:"avatar_url,omitempty"`
}

The User object represents a user in a Notion workspace.

type UserType

type UserType string

UserType is type of User.

const (
	// UserPerson means User objects represent people.
	UserPerson UserType = "person"
	// UserBot means User objects represent bot.
	UserBot UserType = "bot"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL