All Projects → notionsdk → notion-sdk-kotlin-old

notionsdk / notion-sdk-kotlin-old

Licence: other
Unofficial Notion.so API wrapper, written in Kotlin

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to notion-sdk-kotlin-old

notion-heroku
Heroku hosted application that performs Notion actions (i.e., new task, new note) based on voice requests via IFTTT Webhooks and Google Assistant.
Stars: ✭ 41 (-40.58%)
Mutual labels:  notion
icons
a collection of custom icons for use with the notion-enhancer's "icon sets" integration
Stars: ✭ 29 (-57.97%)
Mutual labels:  notion
notion-tqdm
Progress Bar displayed in Notion like tqdm for Python
Stars: ✭ 64 (-7.25%)
Mutual labels:  notion
notion widgets
A set of HTML widgets that could be embedded into Notion.so https://www.notion.so/ pages. For more see https://blog.shorouk.dev/notion-widgets-gallery/
Stars: ✭ 270 (+291.3%)
Mutual labels:  notion
notionapi
A Notion API SDK, written in Golang
Stars: ✭ 351 (+408.7%)
Mutual labels:  notion
notion-instagram
Schedule & Publish posts to Instagram from Notion
Stars: ✭ 115 (+66.67%)
Mutual labels:  notion
notion-cli-list-manager
A simple command-line tool for managing Notion databases.
Stars: ✭ 76 (+10.14%)
Mutual labels:  notion
notion-sdk-php
A complete Notion SDK for PHP developers.
Stars: ✭ 60 (-13.04%)
Mutual labels:  notion
jahir.dev
My personal website 💎 – Built using Next.js, TypeScript, MDX, contentlayer, Notion and Stitches styled components
Stars: ✭ 119 (+72.46%)
Mutual labels:  notion
notion-avatar
🪄 An online tool for making notion-style avatars.
Stars: ✭ 1,687 (+2344.93%)
Mutual labels:  notion
typora notion-theme
My customisations for Typora to look a little more like Notion.so
Stars: ✭ 32 (-53.62%)
Mutual labels:  notion
notion-cms
Notion as a headless CMS
Stars: ✭ 76 (+10.14%)
Mutual labels:  notion
notion-rtl
ARCHIVED - A Chrome extension to enable RTL support in https://notion.so
Stars: ✭ 58 (-15.94%)
Mutual labels:  notion
cards
Turn your Notion database into a deck of cards
Stars: ✭ 37 (-46.38%)
Mutual labels:  notion
open-source-notionapi-apps
Collection of Apps, Integrations und Libraries that utilize the Notion API
Stars: ✭ 82 (+18.84%)
Mutual labels:  notion
notion-scholar
Reference management solution using Python and Notion.
Stars: ✭ 77 (+11.59%)
Mutual labels:  notion
notion-linux-wrapper
Notion.so desktop application for Linux
Stars: ✭ 37 (-46.38%)
Mutual labels:  notion
open-in-notion
Chrome Extension to redirect Notion pages links to the desktop app.
Stars: ✭ 42 (-39.13%)
Mutual labels:  notion
narkdown-py
A tool to use Notion as a Markdown editor.
Stars: ✭ 38 (-44.93%)
Mutual labels:  notion
nobelium
A static blog build on top of Notion and NextJS, deployed on Vercel.
Stars: ✭ 1,790 (+2494.2%)
Mutual labels:  notion

Notion SDK / Kotlin / Unofficial API

Archived: this library depends on the private APIs which are unstable and not really convenient.

Please use https://github.com/notionsdk/notion-sdk-kotlin

Unofficial Notion API wrapper (SDK), written in Kotlin. Can be used in Java.

Install

  • Add jitpack.io to your repositories list
repositories {
    // ...
    maven { url 'https://jitpack.io' }
}
  • Add library to dependencies list
dependencies {
    implementation "com.github.notionsdk:notion-sdk-kotlin:$latestVersion"
}

Latest version: https://github.com/notionsdk/notion-sdk-kotlin/releases

Auth

If you have a password

Just use your email and password:

val notion = Notion.fromEmailAndPassword(
    credentials = NotionCredentials(email = "[email protected]", password = "password"),
    /* ... */
)

If you use a randomly generated passcode

  • Open any notion.so page in browser (e.g. in Google Chrome)
  • Open debugging tools (you must be logged in!)
  • Obtain the token_v2 cookie value of https://www.notion.so/

And then:

val notion = Notion.fromToken(
    token = "your_token",
    /* ... */
)

Get page id

  • Open any page
  • Your link should look like https://www.notion.so/<your_wokspace>/d822369169254cc4a1b2f5bbf3e8b87b
  • Last path part is page id (skip all query params), d822369169254cc4a1b2f5bbf3e8b87b for example above.

Mapping

Source collection:

You can use the pre-defined mapping:

suspend fun main() {
    // you need to provide your httpClient; JsonFeature must be installed!
    val httpClient = HttpClient(CIO) {
        Json { serializer = KotlinxSerializer(kotlinx.serialization.json.Json { ignoreUnknownKeys = true }) }
    }
    val notion = Notion.fromEmailAndPassword(
        NotionCredentials("[email protected]", "password"),
        httpClient  // you need to provide your httpClient; JsonFeature must be installed!
    )

    // different instance for serialization 
    // because Notion's JSON is really weird for statically typed parsing
    val json = Json {
        ignoreUnknownKeys = true

        // you need to use the discriminator if you want to serialize the table back to json
        classDiscriminator = "object_type"
    }
    val table: NotionTable? = notion.getCollection(json, pageId = "73ef0bcb09424b00916e6e4f6759e310")

    println(table)
    // Output:
    // NotionTable(
    //    title=Some test table, 
    //    description=With test description, 
    //    rows=[
    //        NotionRow(
    //            properties={
    //                checked=SingleValue(name=checked, type=Checkbox, value=NotionProperty(label=Yes, value=Checkbox(checked=true))), 
    //                value=SingleValue(name=value, type=Text, value=NotionProperty(label=some_value_0, value=Text(text=some_value_0))), 
    //                key=SingleValue(name=key, type=Title, value=NotionProperty(label=some_key_0, value=Title(text=some_key_0)))
    //            }, 
    //            metaInfo=MetaInfo(lastEditedBy=d6a033eb-82bb-49dd-975c-82ccb739f30e, lastEditedTime=1606352460000, createdBy=d6a033eb-82bb-49dd-975c-82ccb739f30e, createdTime=1606350145225)), 
    //        NotionRow(
    //            properties={
    //                key=SingleValue(name=key, type=Title, value=NotionProperty(label=some_key_1, value=Title(text=some_key_1))), 
    //                value=SingleValue(name=value, type=Text, value=NotionProperty(label=some_value_1, value=Text(text=some_value_1)))
    //            }
    //            metaInfo=MetaInfo(lastEditedBy=d6a033eb-82bb-49dd-975c-82ccb739f30e, lastEditedTime=1606350180000, createdBy=d6a033eb-82bb-49dd-975c-82ccb739f30e, createdTime=1606350145225))
    //    ], 
    //    schema={
    //        key=Title(name=key, type=Title)
    //        checked=Checkbox(name=checked, type=Checkbox), 
    //        value=Text(name=value, type=Text)
    //     }
    // )

    // now the json is much more readable!
    println(json.encodeToString(table))

    // works like a charm as well
    println(json.decodeFromString<NotionTable>(json.encodeToString(table)))
    
    // or even better:
    val simpleJson: List<JsonElement>? = table.simpleJsonRows(json)
    
    println(simpleJson)
    // Output:
    // [{"checked":true,"value":"some_value_0","key":"some_key_0"},{"value":"some_value_1","key":"some_key_1"}]
    
    // map to your model:
    val yourModels = simpleJson?.map { json.decodeFromJsonElement<SomeItem>(it) }
    
    println(yourModels)
    // Output:
    // [SomeItem(key=some_key_0, value=some_value_0, checked=true), SomeItem(key=some_key_1, value=some_value_1, checked=false)]
}

@Serializable
data class SomeItem(
    val key: String,
    val value: String,
    val checked: Boolean = false
)

Supported types of columns:

  • Title, Text, Number, Checkbox, Select, MultiSelect;
  • Person, Link, File, Email, PhoneNumber
  • Date

Unfortunately, Notion API is too dynamically typed to easy cover all the cases for the column types. Also, some types, such as Created by, don't have the property value, but you can access it from the row meta info. They added just because otherwise JSON deserialization will fail (they will appear only in row schema).

Note:

  • sometimes Notion can return almost empty response, so just make a request again;
  • after several requests, auth endpoint will throw 429, limitations are unknown.

Actually the main purpose of the library is to retrieve the data from the Notion database (collection). You can only authenticate and read, but not write or listen for the updates. It uses the private APIs, reverse engineering helped here, so it may sometimes fail, or be even banned when Notion will release their paid APIs. Unfortunately it is the only way to retrieve any info from Notion so far. Use it at your own risk. For educational purposes only.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].