Unofficial iOS/macOS SDK for the Notion API.

Overview

NotionClient: a Notion SDK for iOS & macOS

Unofficial Notion API SDK for iOS & macOS. This is an alpha version and still work in progress.

TODO

Features:

  • Create new pages in a database (WIP)
  • Make all objects copyable (WIP)
  • Add date & formula filters
  • Add Foundation objects for blocks / modifying page contents

Documentation:

  • Add documentation for all methods
  • Add sample project for Objective-C
  • Add sample project for Swift

Support:

  • Add support for macOS
  • Add support for tvOS
  • Add support for watchOS?
  • Add OAuth2 authorization support? (currently not possible due to limitations in redirect URI)

Introduction

NotionClient is a native iOS & macOS SDK for Notion's official API. API responses are automatically converted to native Foundation objects making it a lot easier to read the data coming from Notion. Those same Foundation objects can then be modified and sent back to the API to update the objects. Most objects also have convenience initializers for the most common use cases, e.g. setting a text property with just 1 string in 1 color.

This way, there is never any need to deal with Notion's complex JSON structure directly.

Requirements

  • iOS 11 or above

Installation

NotionClient does not use any external dependencies.

Manually

  1. Open NotionClient.xcodeproj
  2. Build the NotionClient-iOS scheme
  3. Copy the generated NotionClient.framework file to your project

Using CocoaPods

Add NotionClient to your Podfile and run pod install.

# Podfile
platform :ios, '11.0'

target 'YOUR_TARGET_NAME' do
    # Dynamic frameworks is supported but not required
    use_frameworks!
	
    pod 'NotionClient'
end

Usage

Objective-C

Import Notion.h in the implementation files (or in a Prefix header):

#import <NotionClient/Notion.h>

Swift

Import Notion.h in the Objective-C Bridging Header:

// Bridging header
#import <NotionClient/Notion.h>

Documentation

General information

All communication with the Notion API happens by using a NotionClient object. A NotionClient requires an integration token to be able to communicate with the Notion API, see the official Authorization guide for more information on how to create an integration and a token. Multiple NotionClient objects can be used, each using different integration tokens.

Once initialized a NotionClient object can make requests to the Notion API:

  • All requests to the Notion API are asynchronous and will return the result (or error) in a completion handler.
  • If the request was successful, the response will be returned in the completion handler in the form of one or multiple native objects (e.g. NotionPage or NotionUser). These objects are (often simplified) wrappers around the JSON objects that the Notion API returns. These exist to simplify reading and writing data from/to the Notion API. It should never be necessary to deal with JSON directly.
  • If the request has failed, an NSError object will be returned in the completion handler. In case of an API error, the error object's code will be the HTTP status code and the response body containing the error message will be in the userInfo dictionary of the error object.
  • Requests that use pagination are handled automatically by default for simplicity sake. If a response indicates that more items are available, a new request will be made to fetch the next page. This means that calling a function on a NotionClient to get a list may do multiple API requests behind the scenes. The completion handler will return the results of all pages. The page size is set to 100 by default (the maximum) but this can be modified.
  • At the moment there is no way to handle paginated requests manually but this will be added in the future.

For all documentation, visit the Wiki.

Creating a NotionClient

Creating a NotionClient is simple, just pass an integration token and you're good to go.

Swift:

let client = NotionClient.init(token: "NOTION_INTEGRATION_TOKEN")

Objective-C:

NotionClient *client = [NotionClient clientWithToken:@"NOTION_INTEGRATION_TOKEN"];

Getting all users

To get all users in the workspace, you can use NotionClient's getUsers method. This will return an array of NotionUser objects. From there you can get the user's ID, name, email, etc.

Swift:

client.getUsers { (users, error) in
    let user = users?.first
}

Objective-C:

[self.notionClient getUsersWithCompletion:^(NSArray<NotionUser *> * _Nonnull users, NSError * _Nonnull error) {
    NotionUser *user = users.firstObject;
}];

Query a database

To get pages from a database, you can use NotionClient's queryDatabase method. This will return an array of NotionPage objects. From there you can access the page's properties, title, parent, etc.

Swift:

client.queryDatabase(id: "DATABASE_ID") { (pages, error) in
    let page = pages?.first
}

Objective-C:

[self.notionClient queryDatabaseWithId:@"DATABASE_ID" completion:^(NSArray<NotionPage *> * _Nullable pages, NSError * _Nullable error) {
    NotionPage *page = pages.firstObject;
}];

Optionally you can provide a NotionFilter and/or an array of NotionSort objects to either filter results or have them return in a specific order or both.

Swift:

let filter = NotionTextFilter.property("Country", equals: "Belgium")
let sorts = [
    NotionSort.descendingOnProperty(name: "Inhabitants"),
    NotionSort.ascendingOnProperty(name: "City")
]

client.queryDatabase(id: "DATABASE_ID", filter: filter, sorts: sorts) { (page, error) in
    let page = pages?.first
}

Objective-C:

NotionFilter *filter = [NotionTextFilter property:@"Country" equals:@"Belgium"];
NSArray *sorts = @[
    [NotionSort descendingOnProperty:@"Inhabitants"],
    [NotionSort ascendingOnProperty:@"City"]
];

[self.notionClient queryDatabaseWithId:@"DATABASE_ID" filter:filter sorts:sorts completion:^(NSArray<NotionPage *> * _Nullable pages, NSError * _Nullable error) {
    NotionPage *page = pages.firstObject;
}];

To use multiple filters, create a NotionFilterGroup object, which is a collection of multiple NotionFilters. A NotionFilterGroup is also a NotionFilter, so groups can be nested up to 2 levels deep. For more information see the official documentation on Compound Filters.

Swift:

let filter = NotionFilterGroup.orGroup(with: [
    NotionTextFilter.property("Country", equals: "Belgium"),
    NotionFilterGroup.andGroup(with: [
        NotionCheckboxFilter.property("Visited", equals: true),
        NotionFilterGroup.orGroup(with: [
            NotionMultiSelectFilter.property("Languages", contains: "English"),
            NotionFileFilter.propertyIsNotEmpty("Flag")
        ])
    ])
])

Objective-C:

NotionFilter *filter = [NotionFilterGroup orGroupWithFilters:@[
    [NotionTextFilter property:@"Country" equals:@"Belgium"],
    [NotionFilterGroup andGroupWithFilters:@[
        [NotionCheckboxFilter property:@"Visited" equals:YES],
        [NotionFilterGroup orGroupWithFilters:@[
            [NotionMultiSelectFilter property:@"Languages" contains:@"English"],
            [NotionFileFilter propertyIsNotEmpty:@"Flag"]
        ]]
    ]]
]];

More documentation coming soon!

License

NotionClient is released under an MIT License. See LICENSE for details.

You might also like...
Instagram Private API Swift

SwiftyInsta Please notice SwiftyInsta may not be actively maintained at the moment of you reading this note. Refer to #244 for more info. Instagram of

A Swift client for the OpenAI API.

OpenAI A Swift client for the OpenAI API. Requirements Swift 5.3+ An OpenAI API Key Example Usage Completions import OpenAI

Swift Bot with Vapor for Telegram Bot Api

Telegram Vapor Bot Please support Swift Telegram Vapor Bot Lib development by giving a ⭐️ Telegram Bot based on Swift Vapor. Swift Server Side Communi

Swift library for the Twitter API v1 and v2

Swift library for the Twitter API v1 and v2

A (really) native and powerful macOS Telegram client built using SwiftUI, optimized for moderating large communities and personal use.
A (really) native and powerful macOS Telegram client built using SwiftUI, optimized for moderating large communities and personal use.

Moc A (really) native and powerful macOS Telegram client, optimized for moderating large communities and personal use. This client is currently in dev

Swifter - A Twitter framework for iOS & OS X written in Swift
Swifter - A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

The swiftest way to build iOS apps that connect to Salesforce
The swiftest way to build iOS apps that connect to Salesforce

Build iOS apps fast on the Salesforce Platform with Swiftly Salesforce: Written entirely in Swift. Uses Swift's Combine framework to simplify complex,

App iOS correspondiente al proyecto twitimer.com de la comunidad MoureDev
App iOS correspondiente al proyecto twitimer.com de la comunidad MoureDev

⏳ Twitimer iOS Twitimer es una App gratuita para iOS y Android que se ha desarrollado para ayudar a usuarios de Twitch, pero sobre todo pensando en ge

Unofficial iOS/macOS SDK for the Notion API.
Unofficial iOS/macOS SDK for the Notion API.

NotionClient: a Notion SDK for iOS & macOS Unofficial Notion API SDK for iOS & macOS. This is an alpha version and still work in progress. TODO Featur

Unofficial Notion API SDK for iOS & macOS
Unofficial Notion API SDK for iOS & macOS

NotionSwift Unofficial Notion SDK for iOS & macOS. This is still work in progress version, the module interface might change. API Documentation This l

NotionDrive - A swift package that can upload files to Notion.so or download files from Notion.so

NotionDrive NotionDrive is a swift package that can upload files to Notion.so or

The unofficial Instagram iOS SDK

InstagramKit An extensive Objective C wrapper for the Instagram API, completely compatible with Swift. Here's a quick example to retrieve trending med

👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me
👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me

RandomUserSwift is an easy to use Swift framework that provides the ability to generate random users and their accompanying data for your Swift applic

Poly is an unofficial Google Poly SDK, written in Swift

🦕 Unofficial Google Poly SDK in Swift – search, discover, and download 3D models and scenes

👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me
👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me

RandomUserSwift is an easy to use Swift framework that provides the ability to generate random users and their accompanying data for your Swift applic

Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Unofficial Yandex Music API
Unofficial Yandex Music API

YM-API - Unofficial Swift Yandex Music Library Fully ported Yandex Music API Swift implementation. Russian Readme (Readme на русском) Thanks to Marsha

An unofficial supported Swift client library for accessing News API.

An unofficial supported Swift client library for accessing News API.

Unofficial GitHub API client in Swift
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Owner
David De Bels
David De Bels
Fetch Multiple Rest API using Swift 5.5 Async Await with Task, TaskGroup, Continuation API

Source code for Tutorial on experimenting with Swift Async Await to fetch multiple REST API endpoints and eliminate Pyramid of Doom callback hell to improve code readability and maintanability

Alfian Losari 14 Dec 7, 2022
CovidCertificate SDK for iOS

This is the Swiss implementation of the Electronic Health Certificates (EHN) Specification [1] used to verify the validity of Digital Covid Certificates. It is partly based on the reference implementation of EHN's ValidationCore

Swiss Admin 19 Apr 5, 2022
Desk360 Mobile Chat SDK for iOS

Desk360 Chat iOS SDK Desk360 Chat SDK provides simplicity and usability in one place. With this feature, you can provide live support to your customer

null 5 Sep 21, 2022
WANNA SDK enhances your iOS app with virtual try-on capabilities for shoes and watches

WANNA SDK enhances your iOS app with virtual try-on capabilities for shoes and watches. With this feature, your users will be able to see in real time how the selected product looks on them, just by pointing their smartphone camera at their feet or wrist.

Wannaby Inc. 18 Dec 2, 2022
SDK for creating Telegram Bots in Swift.

Chat • Changelog • Prerequisites • Getting started • Creating a new bot • Generating Xcode project • API overview • Debugging notes • Examples • Docum

Rapier 349 Dec 20, 2022
Google Directions API helper for iOS, written in Swift

PXGoogleDirections Google Directions API SDK for iOS, entirely written in Swift. ?? Features Supports all features from the Google Directions API as o

Romain L 268 Aug 18, 2022
Backport of iOS 15 formatting api

This is a back-port of the .formatted API in Foundation that was introduced at WWDC '21 for iOS 15, macOS 12.0, tvOS 15.0, and watchOS 8.0.

Simon Salomons 9 Jul 22, 2022
Swift implementation of Github REST API v3

GitHubAPI Swift implementation of GitHub REST api v3. Library support Swift 4.2. Work is in progress. Currently supported: Issues API. Activity API(Fe

Serhii Londar 77 Jan 7, 2023
Swift Reddit API Wrapper

reddift reddift is Swift Reddit API Wrapper framework, and includes a browser is developed using the framework. Supports OAuth2(is not supported on tv

sonson 236 Dec 28, 2022
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 580 Nov 25, 2022