ThinNotionApi.Databases (thin_notion_api v0.0.1) View Source

Module for interacting with the Notion Databases.

Link to this section Summary

Functions

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request. The response may contain fewer than page_size of results.

List all Databases shared with the authenticated integration. The response may contain fewer than page_size of results.

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request. The response may contain fewer than page_size of results.

Retrieves a Database object using the ID specified.

Link to this section Functions

Link to this function

create_database!(parent_id, title, properties \\ %{Name: %{title: %{}}})

View Source

Specs

create_database!(atom(), String.t(), map()) :: any()

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request. The response may contain fewer than page_size of results.

Examples:

iex> ThinNotionApi.Databases.create_database!("9b4a624d5a18482ab2187e54166edda7", "New Database")
{:ok,
  %{
    "created_time" => "2021-07-30T20:44:00.000Z",
    "id" => "99315749-1f39-4095-9a40-449876f23f95",
    "last_edited_time" => "2021-07-30T20:44:00.000Z",
    "object" => "database",
    "parent" => %{
      "page_id" => "9b4a624d-5a18-482a-b218-7e54166edda7",
      "type" => "page_id"
    },
    "properties" => %{
      "Name" => %{
        "id" => "title",
        "name" => "Name",
        "title" => %{},
        "type" => "title"
      }
    },
    "title" => [
      %{
        "annotations" => %{
          "bold" => false,
          "code" => false,
          "color" => "default",
          "italic" => false,
          "strikethrough" => false,
          "underline" => false
        },
        "href" => nil,
        "plain_text" => "New Database",
        "text" => %{"content" => "New Database", "link" => nil},
        "type" => "text"
      }
    ]
  }
}
Link to this function

list_databases(query_params \\ %{})

View Source

List all Databases shared with the authenticated integration. The response may contain fewer than page_size of results.

Use search pages for more details.

This endpoint is no longer recommended, use search instead. This endpoint will only return explicitly shared pages, while search will also return child pages within explicitly shared pages. This endpoint's results cannot be filtered, while search can be used to match on page title.

Examples:

iex> ThinNotionApi.Databases.list_databases(query_params)
Link to this function

query_database(database_id, body_params \\ %{})

View Source

Gets a list of Pages contained in the database, filtered and ordered according to the filter conditions and sort criteria provided in the request. The response may contain fewer than page_size of results.

Examples:

iex> ThinNotionApi.Databases.query_database(database_id)
{:ok,
  %{
    "has_more" => false,
    "next_cursor" => nil,
    "object" => "list",
    "results" => [
      %{
        "archived" => false,
        "created_time" => "2021-06-11T20:34:00.000Z",
        "id" => "0a8f7171-00b7-4f7e-a0b5-155f006186bb",
        "last_edited_time" => "2021-07-16T21:04:00.000Z",
        "object" => "page",
        "parent" => %{
          "database_id" => "a4ef92b2-a798-4bae-8211-4817678cd2f4",
          "type" => "database_id"
        },
        "properties" => %{
          "Name" => %{
            "id" => "title",
            "title" => [
              %{
                "annotations" => %{
                  "bold" => false,
                  "code" => false,
                  "color" => "default",
                  "italic" => false,
                  "strikethrough" => false,
                  "underline" => false
                },
                "href" => nil,
                "plain_text" => "Hello World",
                "text" => %{"content" => "Hello World", "link" => nil},
                "type" => "text"
              }
            ],
            "type" => "title"
          }
        },
        "url" => "https://www.notion.so/Hello-World-0a8f717100b74f7ea0b5155f006186bb"
      },
      ...
    ]
  }
}

iex> ThinNotionApi.Databases.query_database("a4ef92b2a7984bae82114817678cd2f4", %{ "page_size" => 1})
{:ok,
  %{
    "has_more" => true,
    "next_cursor" => "700b4e34-697c-4fad-b97d-d9741d1fbaeb",
    "object" => "list",
    "results" => [
      %{
        "archived" => false,
        "created_time" => "2021-06-11T20:34:00.000Z",
        "id" => "0a8f7171-00b7-4f7e-a0b5-155f006186bb",
        "last_edited_time" => "2021-07-16T21:04:00.000Z",
        "object" => "page",
        "parent" => %{
          "database_id" => "a4ef92b2-a798-4bae-8211-4817678cd2f4",
          "type" => "database_id"
        },
        "properties" => %{
          "Name" => %{
            "id" => "title",
            "title" => [
              %{
                "annotations" => %{
                  "bold" => false,
                  "code" => false,
                  "color" => "default",
                  "italic" => false,
                  "strikethrough" => false,
                  "underline" => false
                },
                "href" => nil,
                "plain_text" => "Hello World",
                "text" => %{"content" => "Hello World", "link" => nil},
                "type" => "text"
              }
            ],
            "type" => "title"
          }
        },
        "url" => "https://www.notion.so/Hello-World-0a8f717100b74f7ea0b5155f006186bb"
      }
    ]
  }}
Link to this function

retrieve_database(database_id)

View Source

Retrieves a Database object using the ID specified.

Examples

iex> ThinNotionApi.Databases.retrieve_database(database_id)
{:ok,
%{
  "created_time" => "2021-06-11T20:34:00.000Z",
  "id" => "a4ef92b2-a798-4bae-8211-4817678cd2f4",
  "last_edited_time" => "2021-07-16T20:44:00.000Z",
  "object" => "database",
  "parent" => %{
    "page_id" => "9b4a624d-5a18-482a-b218-7e54166edda7",
    "type" => "page_id"
  },
  "properties" => %{
    "Name" => %{"id" => "title", "title" => %{}, "type" => "title"},
    "Tags" => %{
      "id" => "@Tnd",
      "multi_select" => %{"options" => []},
      "type" => "multi_select"
    }
  },
  "title" => [
    %{
      "annotations" => %{
        "bold" => false,
        "code" => false,
        "color" => "default",
        "italic" => false,
        "strikethrough" => false,
        "underline" => false
      },
      "href" => nil,
      "plain_text" => "Test Database",
      "text" => %{"content" => "Test Database", "link" => nil},
      "type" => "text"
    }
  ]
}}