Skip to content

hwatkins/ex_notion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExNotion

ex_notion is an Elixir client for the Notion REST API.

Installation

Add ex_notion to your dependencies in mix.exs:

def deps do
  [
    {:ex_notion, "~> 0.1.0"}
  ]
end

Quick Start

client = ExNotion.new_client(System.fetch_env!("NOTION_API_KEY"))

{:ok, me} = ExNotion.Users.me(client)
{:ok, users} = ExNotion.Users.list(client)

Client

client = ExNotion.Client.new("ntn_secret_...",
  version: "2022-06-28",
  base_url: "https://api.notion.com"
)

ExNotion.Client normalizes responses to:

  • {:ok, map} for 2xx responses
  • {:error, %ExNotion.Error{}} for API and transport failures

Resources

Implemented resource modules:

  • ExNotion.Users
  • ExNotion.Databases
  • ExNotion.Pages
  • ExNotion.Blocks
  • ExNotion.Comments
  • ExNotion.Search

Examples:

{:ok, db} = ExNotion.Databases.get(client, "database-id")

{:ok, result} =
  ExNotion.Databases.query(client, "database-id", %{
    filter: %{property: "Status", status: %{equals: "Done"}},
    page_size: 10
  })

{:ok, page} = ExNotion.Pages.create(client, %{
  parent: %{database_id: "database-id"},
  properties: %{Name: %{title: [%{text: %{content: "Hello"}}]}}
})

Pagination

ExNotion.Pagination.all_pages/4 provides cursor-based aggregation across Notion list responses.

{:ok, all_users} = ExNotion.Pagination.all_pages(client, :get, "/v1/users", %{})

Builders

ExNotion.RichText and ExNotion.BlockBuilder help build Notion payloads.

import ExNotion.RichText
import ExNotion.BlockBuilder

rich = [text("Hello"), text(" world", bold: true)]

blocks = [
  heading_1("My Doc"),
  paragraph(rich),
  to_do("Ship release", checked: false),
  divider(),
  callout("!", "Important")
]

Development

mix ci.fast
mix ci

License

MIT

About

Elixir client library for the Notion REST API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages