notion

package module
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 10 Imported by: 1

README

go-notion

GitHub tag (latest SemVer) Go Reference GitHub Go Report Card

go-notion is a client for the Notion API, written in Go.

Features

The client supports all (non-deprecated) endpoints available in the Notion API, as of July 20, 2021:

Installation

$ go get github.com/dstotijn/go-notion

Getting started

To obtain an API key, follow Notion’s getting started guide.

Code example

First, construct a new Client:

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

(...)

client := notion.NewClient("secret-api-key")

Then, use the methods defined on Client to make requests to the API. For example:

page, err := client.FindPageByID(context.Background(), "18d35eb5-91f1-4dcb-85b0-c340fd965015")
if err != nil {
    // Handle error...
}

👉 Check out the docs on pkg.go.dev for further reference and examples.

Status

The Notion API is currently in public beta.

⚠️ Although the API itself is versioned, this client will make breaking changes in its code until v1.0 of the module is released.

To do
  • Write tests
  • Provide examples

License

MIT License


© 2021 David Stotijn — Twitter, Email

Documentation

Index

Constants

View Source
const (
	// Database property type enums.
	DBPropTypeTitle          DatabasePropertyType = "title"
	DBPropTypeRichText       DatabasePropertyType = "rich_text"
	DBPropTypeNumber         DatabasePropertyType = "number"
	DBPropTypeSelect         DatabasePropertyType = "select"
	DBPropTypeMultiSelect    DatabasePropertyType = "multi_select"
	DBPropTypeDate           DatabasePropertyType = "date"
	DBPropTypePeople         DatabasePropertyType = "people"
	DBPropTypeFiles          DatabasePropertyType = "files"
	DBPropTypeCheckbox       DatabasePropertyType = "checkbox"
	DBPropTypeURL            DatabasePropertyType = "url"
	DBPropTypeEmail          DatabasePropertyType = "email"
	DBPropTypePhoneNumber    DatabasePropertyType = "phone_number"
	DBPropTypeFormula        DatabasePropertyType = "formula"
	DBPropTypeRelation       DatabasePropertyType = "relation"
	DBPropTypeRollup         DatabasePropertyType = "rollup"
	DBPropTypeCreatedTime    DatabasePropertyType = "created_time"
	DBPropTypeCreatedBy      DatabasePropertyType = "created_by"
	DBPropTypeLastEditedTime DatabasePropertyType = "last_edited_time"
	DBPropTypeLastEditedBy   DatabasePropertyType = "last_edited_by"

	// Number format enums.
	NumberFormatNumber           NumberFormat = "number"
	NumberFormatNumberWithCommas NumberFormat = "number_with_commas"
	NumberFormatPercent          NumberFormat = "percent"
	NumberFormatDollar           NumberFormat = "dollar"
	NumberFormatEuro             NumberFormat = "euro"
	NumberFormatPound            NumberFormat = "pound"
	NumberFormatPonud            NumberFormat = "yen"
	NumberFormatRuble            NumberFormat = "ruble"
	NumberFormatRupee            NumberFormat = "rupee"
	NumberFormatWon              NumberFormat = "won"
	NumberformatYuan             NumberFormat = "yuan"

	// Formula result type enums.
	FormulaResultTypeString  FormulaResultType = "string"
	FormulaResultTypeNumber  FormulaResultType = "number"
	FormulaResultTypeBoolean FormulaResultType = "boolean"
	FormulaResultTypeDate    FormulaResultType = "date"

	// Rollup result type enums.
	RollupResultTypeNumber RollupResultType = "number"
	RollupResultTypeDate   RollupResultType = "date"
	RollupResultTypeArray  RollupResultType = "array"

	// Sort timestamp enums.
	SortTimeStampCreatedTime    SortTimestamp = "created_time"
	SortTimeStampLastEditedTime SortTimestamp = "last_edited_time"

	// Sort direction enums.
	SortDirAsc  SortDirection = "ascending"
	SortDirDesc SortDirection = "descending"
)
View Source
const DateTimeFormat = "2006-01-02T15:04:05.999Z07:00"

DateTimeFormat is used when calling time.Parse, using RFC3339 with microsecond precision, which is what the Notion API returns in JSON response data.

Variables

View Source
var (
	ErrInvalidJSON        = errors.New("notion: request body could not be decoded as JSON")
	ErrInvalidRequestURL  = errors.New("notion: request URL is not valid")
	ErrInvalidRequest     = errors.New("notion: request is not supported")
	ErrValidation         = errors.New("notion: request body does not match the schema for the expected parameters")
	ErrUnauthorized       = errors.New("notion: bearer token is not valid")
	ErrRestrictedResource = errors.New("notion: client doesn't have permission to perform this operation")
	ErrObjectNotFound     = errors.New("notion: the resource does not exist")
	ErrConflict           = errors.New("notion: the transaction could not be completed, potentially due to a data collision")
	ErrRateLimited        = errors.New("notion: this request exceeds the number of requests allowed")
	ErrInternalServer     = errors.New("notion: an unexpected error occurred")
	ErrServiceUnavailable = errors.New("notion: service is unavailable")
)

See: https://developers.notion.com/reference/errors.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns the pointer of a bool value.

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr returns the pointer of a float64 value.

func IntPtr

func IntPtr(i int) *int

IntPtr returns the pointer of an int value.

func StringPtr

func StringPtr(s string) *string

StringPtr returns the pointer of a string value.

func TimePtr

func TimePtr(t time.Time) *time.Time

TimePtr returns the pointer of a time.Time value.

Types

type APIError

type APIError struct {
	Object  string `json:"object"`
	Status  int    `json:"status"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (*APIError) Error

func (err *APIError) Error() string

Error implements `error`.

func (*APIError) Unwrap

func (err *APIError) Unwrap() error

type Annotations

type Annotations struct {
	Bold          bool  `json:"bold,omitempty"`
	Italic        bool  `json:"italic,omitempty"`
	Strikethrough bool  `json:"strikethrough,omitempty"`
	Underline     bool  `json:"underline,omitempty"`
	Code          bool  `json:"code,omitempty"`
	Color         Color `json:"color,omitempty"`
}

type Block

type Block struct {
	Object         string     `json:"object"`
	ID             string     `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"`

	Paragraph        *RichTextBlock `json:"paragraph,omitempty"`
	Heading1         *Heading       `json:"heading_1,omitempty"`
	Heading2         *Heading       `json:"heading_2,omitempty"`
	Heading3         *Heading       `json:"heading_3,omitempty"`
	BulletedListItem *RichTextBlock `json:"bulleted_list_item,omitempty"`
	NumberedListItem *RichTextBlock `json:"numbered_list_item,omitempty"`
	ToDo             *ToDo          `json:"to_do,omitempty"`
	Toggle           *RichTextBlock `json:"toggle,omitempty"`
	ChildPage        *ChildPage     `json:"child_page,omitempty"`
}

Block represents content on the Notion platform. See: https://developers.notion.com/reference/block

func (Block) MarshalJSON

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

MarshalJSON implements json.Marshaler.

type BlockChildrenResponse

type BlockChildrenResponse struct {
	Results    []Block `json:"results"`
	HasMore    bool    `json:"has_more"`
	NextCursor *string `json:"next_cursor"`
}

BlockChildrenResponse contains results (block children) and pagination data returned from a find request.

type BlockType

type BlockType string
const (
	BlockTypeParagraph        BlockType = "paragraph"
	BlockTypeHeading1         BlockType = "heading_1"
	BlockTypeHeading2         BlockType = "heading_2"
	BlockTypeHeading3         BlockType = "heading_3"
	BlockTypeBulletedListItem BlockType = "bulleted_list_item"
	BlockTypeNumberedListItem BlockType = "numbered_list_item"
	BlockTypeToDo             BlockType = "to_do"
	BlockTypeToggle           BlockType = "toggle"
	BlockTypeChildPage        BlockType = "child_page"
	BlockTypeUnsupported      BlockType = "unsupported"
)

type Bot

type Bot struct{}

type CheckboxDatabaseQueryFilter

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

type ChildPage

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

type Client

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

Client is used for HTTP requests to the Notion API.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) *Client

NewClient returns a new Client.

func (*Client) AppendBlockChildren

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

AppendBlockChildren appends child content (blocks) to an existing block. See: https://developers.notion.com/reference/patch-block-children

func (*Client) CreateDatabase

func (c *Client) CreateDatabase(ctx context.Context, params CreateDatabaseParams) (db Database, err error)

CreateDatabase creates a new database as a child of an existing page. See: https://developers.notion.com/reference/create-a-database

func (*Client) CreatePage

func (c *Client) CreatePage(ctx context.Context, params CreatePageParams) (page Page, err error)

CreatePage creates a new page in the specified database or as a child of an existing page. See: https://developers.notion.com/reference/post-page

func (*Client) FindBlockChildrenByID

func (c *Client) FindBlockChildrenByID(ctx context.Context, blockID string, query *PaginationQuery) (result BlockChildrenResponse, err error)

FindBlockChildrenByID returns a list of block children for a given block ID. See: https://developers.notion.com/reference/post-database-query

func (*Client) FindDatabaseByID

func (c *Client) FindDatabaseByID(ctx context.Context, id string) (db Database, err error)

FindDatabaseByID fetches a database by ID. See: https://developers.notion.com/reference/get-database

func (*Client) FindPageByID

func (c *Client) FindPageByID(ctx context.Context, id string) (page Page, err error)

FindPageByID fetches a page by ID. See: https://developers.notion.com/reference/get-page

func (*Client) FindUserByID

func (c *Client) FindUserByID(ctx context.Context, id string) (user User, err error)

FindUserByID fetches a user by ID. See: https://developers.notion.com/reference/get-user

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, query *PaginationQuery) (result ListUsersResponse, err error)

ListUsers returns a list of all users, and pagination metadata. See: https://developers.notion.com/reference/get-users

func (*Client) QueryDatabase

func (c *Client) QueryDatabase(ctx context.Context, id string, query *DatabaseQuery) (result DatabaseQueryResponse, err error)

QueryDatabase returns database contents, with optional filters, sorts and pagination. See: https://developers.notion.com/reference/post-database-query

func (*Client) Search

func (c *Client) Search(ctx context.Context, opts *SearchOpts) (result SearchResponse, err error)

Search fetches all pages and child pages that are shared with the integration. Optionally uses query, filter and pagination options. See: https://developers.notion.com/reference/post-search

func (*Client) UpdatePageProps

func (c *Client) UpdatePageProps(ctx context.Context, pageID string, params UpdatePageParams) (page Page, err error)

UpdatePageProps updates page property values for a page. See: https://developers.notion.com/reference/patch-page

type ClientOption

type ClientOption func(*Client)

ClientOption is used to override default client behavior.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient overrides the default http.Client.

type Color

type Color string
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"
	ColorGrayBg   Color = "gray_background"
	ColorBrownBg  Color = "brown_background"
	ColorOrangeBg Color = "orange_background"
	ColorYellowBg Color = "yellow_background"
	ColorGreenBg  Color = "green_background"
	ColorBlueBg   Color = "blue_background"
	ColorPurpleBg Color = "purple_background"
	ColorPinkBg   Color = "pink_background"
	ColorRedBg    Color = "red_background"
)

type CreateDatabaseParams

type CreateDatabaseParams struct {
	ParentPageID string
	Title        []RichText
	Properties   DatabaseProperties
}

CreateDatabaseParams are the params used for creating a database.

func (CreateDatabaseParams) MarshalJSON

func (p CreateDatabaseParams) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (CreateDatabaseParams) Validate

func (p CreateDatabaseParams) Validate() error

Validate validates params for creating a database.

type CreatePageParams

type CreatePageParams struct {
	ParentType ParentType
	ParentID   string

	// Either DatabasePageProperties or Title must be not nil.
	DatabasePageProperties *DatabasePageProperties
	Title                  []RichText

	// Optionally, children blocks are added to the page.
	Children []Block
}

CreatePageParams are the params used for creating a page.

func (CreatePageParams) MarshalJSON

func (p CreatePageParams) MarshalJSON() ([]byte, error)

func (CreatePageParams) Validate

func (p CreatePageParams) Validate() error

type Database

type Database struct {
	ID             string             `json:"id"`
	CreatedTime    time.Time          `json:"created_time"`
	LastEditedTime time.Time          `json:"last_edited_time"`
	Title          []RichText         `json:"title"`
	Properties     DatabaseProperties `json:"properties"`
	Parent         Parent             `json:"parent"`
}

Database is a resource on the Notion platform. See: https://developers.notion.com/reference/database

type DatabasePageProperties

type DatabasePageProperties map[string]DatabasePageProperty

DatabasePageProperties are properties of a page whose parent is a database.

type DatabasePageProperty

type DatabasePageProperty struct {
	ID   string               `json:"id,omitempty"`
	Type DatabasePropertyType `json:"type,omitempty"`

	Title          []RichText      `json:"title,omitempty"`
	RichText       []RichText      `json:"rich_text,omitempty"`
	Number         *float64        `json:"number,omitempty"`
	Select         *SelectOptions  `json:"select,omitempty"`
	MultiSelect    []SelectOptions `json:"multi_select,omitempty"`
	Date           *Date           `json:"date,omitempty"`
	Formula        *FormulaResult  `json:"formula,omitempty"`
	Relation       []Relation      `json:"relation,omitempty"`
	Rollup         *RollupResult   `json:"rollup,omitempty"`
	People         []User          `json:"people,omitempty"`
	Files          []File          `json:"files,omitempty"`
	Checkbox       *bool           `json:"checkbox,omitempty"`
	URL            *string         `json:"url,omitempty"`
	Email          *string         `json:"email,omitempty"`
	PhoneNumber    *string         `json:"phone_number,omitempty"`
	CreatedTime    *time.Time      `json:"created_time,omitempty"`
	CreatedBy      *User           `json:"created_by,omitempty"`
	LastEditedTime *time.Time      `json:"last_edited_time,omitempty"`
	LastEditedBy   *User           `json:"last_edited_by,omitempty"`
}

func (DatabasePageProperty) Value

func (prop DatabasePageProperty) Value() interface{}

Value returns the underlying database page property value, based on its `type` field. When type is unknown/unmapped or doesn't have a value, `nil` is returned.

type DatabaseProperties

type DatabaseProperties map[string]DatabaseProperty

DatabaseProperties is a mapping of properties defined on a database.

type DatabaseProperty

type DatabaseProperty struct {
	ID   string               `json:"id,omitempty"`
	Type DatabasePropertyType `json:"type"`

	Title          *EmptyMetadata `json:"title,omitempty"`
	RichText       *EmptyMetadata `json:"rich_text,omitempty"`
	Date           *EmptyMetadata `json:"date,omitempty"`
	People         *EmptyMetadata `json:"people,omitempty"`
	Files          *EmptyMetadata `json:"files,omitempty"`
	Checkbox       *EmptyMetadata `json:"checkbox,omitempty"`
	URL            *EmptyMetadata `json:"url,omitempty"`
	Email          *EmptyMetadata `json:"email,omitempty"`
	PhoneNumber    *EmptyMetadata `json:"phone_number,omitempty"`
	CreatedTime    *EmptyMetadata `json:"created_time,omitempty"`
	CreatedBy      *EmptyMetadata `json:"created_by,omitempty"`
	LastEditedTime *EmptyMetadata `json:"last_edited_time,omitempty"`
	LastEditedBy   *EmptyMetadata `json:"last_edited_by,omitempty"`

	Number      *NumberMetadata   `json:"number,omitempty"`
	Select      *SelectMetadata   `json:"select,omitempty"`
	MultiSelect *SelectMetadata   `json:"multi_select,omitempty"`
	Formula     *FormulaMetadata  `json:"formula,omitempty"`
	Relation    *RelationMetadata `json:"relation,omitempty"`
	Rollup      *RollupMetadata   `json:"rollup,omitempty"`
}

func (DatabaseProperty) Metadata

func (prop DatabaseProperty) Metadata() interface{}

Metadata returns the underlying property metadata, based on its `type` field. When type is unknown/unmapped or doesn't have additional properies, `nil` is returned.

type DatabasePropertyType

type DatabasePropertyType string

type DatabaseQuery

type DatabaseQuery struct {
	Filter      *DatabaseQueryFilter `json:"filter,omitempty"`
	Sorts       []DatabaseQuerySort  `json:"sorts,omitempty"`
	StartCursor string               `json:"start_cursor,omitempty"`
	PageSize    int                  `json:"page_size,omitempty"`
}

DatabaseQuery is used for quering a database.

type DatabaseQueryFilter

type DatabaseQueryFilter struct {
	Property string `json:"property,omitempty"`

	Text        *TextDatabaseQueryFilter        `json:"text,omitempty"`
	Number      *NumberDatabaseQueryFilter      `json:"number,omitempty"`
	Checkbox    *CheckboxDatabaseQueryFilter    `json:"checkbox,omitempty"`
	Select      *SelectDatabaseQueryFilter      `json:"select,omitempty"`
	MultiSelect *MultiSelectDatabaseQueryFilter `json:"multi_select,omitempty"`
	Date        *DateDatabaseQueryFilter        `json:"date,omitempty"`
	People      *PeopleDatabaseQueryFilter      `json:"people,omitempty"`
	Files       *FilesDatabaseQueryFilter       `json:"files,omitempty"`
	Relation    *RelationDatabaseQueryFilter    `json:"relation,omitempty"`

	Or  []DatabaseQueryFilter `json:"or,omitempty"`
	And []DatabaseQueryFilter `json:"and,omitempty"`
}

DatabaseQueryFilter is used to filter database contents. See: https://developers.notion.com/reference/post-database-query#post-database-query-filter

type DatabaseQueryResponse

type DatabaseQueryResponse struct {
	Results    []Page  `json:"results"`
	HasMore    bool    `json:"has_more"`
	NextCursor *string `json:"next_cursor"`
}

DatabaseQueryResponse contains the results and pagination data from a query request.

type DatabaseQuerySort

type DatabaseQuerySort struct {
	Property  string        `json:"property,omitempty"`
	Timestamp SortTimestamp `json:"timestamp,omitempty"`
	Direction SortDirection `json:"direction,omitempty"`
}

type Date

type Date struct {
	Start DateTime  `json:"start"`
	End   *DateTime `json:"end,omitempty"`
}

type DateDatabaseQueryFilter

type DateDatabaseQueryFilter 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"`
	PastWeek   *struct{}  `json:"past_week,omitempty"`
	PastMonth  *struct{}  `json:"past_month,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"`
}

type DateTime

type DateTime struct {
	time.Time
	// contains filtered or unexported fields
}

DateTime represents a Notion date property with optional time.

func NewDateTime

func NewDateTime(t time.Time, hasTime bool) DateTime

NewDateTime returns a new DateTime. If `haseTime` is true, time is included when encoding to JSON.

func ParseDateTime

func ParseDateTime(value string) (DateTime, error)

ParseDateTime parses an RFC3339 formatted string with optional time.

func (DateTime) Equal

func (dt DateTime) Equal(value DateTime) bool

Equal returns true if both DateTime values have equal underlying time.Time and hasTime fields.

func (*DateTime) HasTime

func (dt *DateTime) HasTime() bool

HasTime returns true if the datetime was parsed from a string that included time.

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It returns an RFC399 formatted string, using microsecond precision ()

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type EmptyMetadata

type EmptyMetadata struct{}

Database property metadata types.

type Equation

type Equation struct {
	Expression string `json:"expression"`
}

type File

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

type FilesDatabaseQueryFilter

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

type FormulaDatabaseQueryFilter

type FormulaDatabaseQueryFilter struct {
	Text     TextDatabaseQueryFilter     `json:"text,omitempty"`
	Checkbox CheckboxDatabaseQueryFilter `json:"checkbox,omitempty"`
	Number   NumberDatabaseQueryFilter   `json:"number,omitempty"`
	Date     DateDatabaseQueryFilter     `json:"date,omitempty"`
}

type FormulaMetadata

type FormulaMetadata struct {
	Expression string `json:"expression"`
}

Database property metadata types.

type FormulaResult

type FormulaResult struct {
	Type FormulaResultType `json:"type"`

	String  *string  `json:"string,omitempty"`
	Number  *float64 `json:"number,omitempty"`
	Boolean *bool    `json:"boolean,omitempty"`
	Date    *Date    `json:"date,omitempty"`
}

func (FormulaResult) Value

func (f FormulaResult) Value() interface{}

Value returns the underlying result value of an evaluated formula.

type FormulaResultType

type FormulaResultType string

type Heading

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

type ID

type ID struct {
	ID string `json:"id"`
}
type Link struct {
	URL string `json:"url"`
}

type ListUsersResponse

type ListUsersResponse struct {
	Results    []User  `json:"results"`
	HasMore    bool    `json:"has_more"`
	NextCursor *string `json:"next_cursor"`
}

ListUsersResponse contains results (users) and pagination data returned from a list request.

type Mention

type Mention struct {
	Type MentionType `json:"type"`

	User     *User `json:"user,omitempty"`
	Page     *ID   `json:"page,omitempty"`
	Database *ID   `json:"database,omitempty"`
	Date     *Date `json:"date,omitempty"`
}

type MentionType

type MentionType string
const (
	MentionTypeUser     MentionType = "user"
	MentionTypePage     MentionType = "page"
	MentionTypeDatabase MentionType = "database"
	MentionTypeDate     MentionType = "date"
)

type MultiSelectDatabaseQueryFilter

type MultiSelectDatabaseQueryFilter 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"`
}

type NumberDatabaseQueryFilter

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

type NumberFormat

type NumberFormat string

type NumberMetadata

type NumberMetadata struct {
	Format NumberFormat `json:"format"`
}

Database property metadata types.

type Page

type Page struct {
	ID             string    `json:"id"`
	CreatedTime    time.Time `json:"created_time"`
	LastEditedTime time.Time `json:"last_edited_time"`
	Parent         Parent    `json:"parent"`
	Archived       bool      `json:"archived"`
	URL            string    `json:"url"`

	// Properties differ between parent type.
	// See the `UnmarshalJSON` method.
	Properties interface{} `json:"properties"`
}

Page is a resource on the Notion platform. Its parent is either a workspace, another page, or a database. See: https://developers.notion.com/reference/page

func (*Page) UnmarshalJSON

func (p *Page) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

Pages get a different Properties type based on the parent of the page. If parent type is `workspace` or `page_id`, PageProperties is used. Else if parent type is `database_id`, DatabasePageProperties is used.

type PageProperties

type PageProperties struct {
	Title PageTitle `json:"title"`
}

PageProperties are properties of a page whose parent is a page or a workspace.

type PageTitle

type PageTitle struct {
	Title []RichText `json:"title"`
}

type PaginationQuery

type PaginationQuery struct {
	StartCursor string
	PageSize    int
}

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"`
}

type ParentType

type ParentType string
const (
	ParentTypeDatabase  ParentType = "database_id"
	ParentTypePage      ParentType = "page_id"
	ParentTypeWorkspace ParentType = "workspace"
)

type People

type People struct {
	People []User `json:"people"`
}

type PeopleDatabaseQueryFilter

type PeopleDatabaseQueryFilter 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"`
}

type Person

type Person struct {
	Email string `json:"email"`
}

type Relation

type Relation struct {
	ID string `json:"id"`
}

type RelationDatabaseQueryFilter

type RelationDatabaseQueryFilter 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"`
}

type RelationMetadata

type RelationMetadata struct {
	DatabaseID     string `json:"database_id,omitempty"`
	SyncedPropName string `json:"synced_property_name,omitempty"`
	SyncedPropID   string `json:"synced_property_id,omitempty"`
}

Database property metadata types.

type RichText

type RichText struct {
	Type        RichTextType `json:"type,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`

	PlainText string    `json:"plain_text,omitempty"`
	HRef      *string   `json:"href,omitempty"`
	Text      *Text     `json:"text,omitempty"`
	Mention   *Mention  `json:"mention,omitempty"`
	Equation  *Equation `json:"equation,omitempty"`
}

type RichTextBlock

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

type RichTextType

type RichTextType string
const (
	RichTextTypeText     RichTextType = "text"
	RichTextTypeMention  RichTextType = "mention"
	RichTextTypeEquation RichTextType = "equation"
)

type RollupMetadata

type RollupMetadata struct {
	RelationPropName string `json:"relation_property_name,omitempty"`
	RelationPropID   string `json:"relation_property_id,omitempty"`
	RollupPropName   string `json:"rollup_property_name,omitempty"`
	RollupPropID     string `json:"rollup_property_id,omitempty"`
	Function         string `json:"function,omitempty"`
}

Database property metadata types.

type RollupResult

type RollupResult struct {
	Type RollupResultType `json:"type"`

	Number *float64               `json:"number,omitempty"`
	Date   *Date                  `json:"date,omitempty"`
	Array  []DatabasePageProperty `json:"array,omitempty"`
}

func (RollupResult) Value

func (r RollupResult) Value() interface{}

Value returns the underlying result value of an evaluated rollup.

type RollupResultType

type RollupResultType string

type SearchFilter

type SearchFilter struct {
	Value    string `json:"value"`
	Property string `json:"property"`
}

type SearchOpts

type SearchOpts struct {
	Query       string        `json:"query,omitempty"`
	Sort        *SearchSort   `json:"sort,omitempty"`
	Filter      *SearchFilter `json:"filter,omitempty"`
	StartCursor string        `json:"start_cursor,omitempty"`
	PageSize    int           `json:"page_size,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	// Results are either pages or databases. See `SearchResponse.UnmarshalJSON`.
	Results    SearchResults `json:"results"`
	HasMore    bool          `json:"has_more"`
	NextCursor *string       `json:"next_cursor"`
}

type SearchResults

type SearchResults []interface{}

func (*SearchResults) UnmarshalJSON

func (sr *SearchResults) UnmarshalJSON(b []byte) error

type SearchSort

type SearchSort struct {
	Direction SortDirection       `json:"direction,omitempty"`
	Timestamp SearchSortTimestamp `json:"timestamp"`
}

type SearchSortTimestamp

type SearchSortTimestamp string
const SearchSortTimestampLastEditedTime SearchSortTimestamp = "last_edited_time"

type SelectDatabaseQueryFilter

type SelectDatabaseQueryFilter 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"`
}

type SelectMetadata

type SelectMetadata struct {
	Options []SelectOptions `json:"options"`
}

Database property metadata types.

type SelectOptions

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

type SortDirection

type SortDirection string

type SortTimestamp

type SortTimestamp string

type Text

type Text struct {
	Content string `json:"content"`
	Link    *Link  `json:"link,omitempty"`
}

type TextDatabaseQueryFilter

type TextDatabaseQueryFilter 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"`
}

type ToDo

type ToDo struct {
	RichTextBlock
	Checked *bool `json:"checked,omitempty"`
}

type UpdatePageParams

type UpdatePageParams struct {
	// Either DatabasePageProperties or Title must be not nil.
	DatabasePageProperties *DatabasePageProperties
	Title                  []RichText
}

func (UpdatePageParams) MarshalJSON

func (p UpdatePageParams) MarshalJSON() ([]byte, error)

func (UpdatePageParams) Validate

func (p UpdatePageParams) Validate() error

type User

type User struct {
	ID        string  `json:"id"`
	Type      string  `json:"type"`
	Name      string  `json:"name"`
	AvatarURL *string `json:"avatar_url"`

	Person *Person `json:"person"`
	Bot    *Bot    `json:"bot"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto