Giter Club home page Giter Club logo

rest-notion-db's Introduction

rest-notion-db

A RESTful way to use your Notion tables as a database.

UPDATE

As of May 11, 2021, the official Notion API is available in its public beta version. I'd recommend you to use that.

Use-cases

Form submissions or frontend websites, use one database that is understood by everyone at your workplace for all your needs.

Usage

In order to use the API, you need to provide your Notion token_v2 cookie and the Notion database page URL. You can obtain your token_v2 using Chrome DevTools or the like for other browsers.

GET data

Endpoint: /page/<PAGE_ID>
The PAGE_ID includes the ID of the page along with the default ?v URL parameter.

Simply replace the notion.so to rest-notion-db.herokuapp.com on your database page to access the table data as a JSON response.

In case of an auth-secured page, send your token_v2 cookie as a Authorization Bearer Token header in the request.

Queries
Currently, you can sort and limit the data using request parameters.

For example:
?name=asc: sorts all the names in alphabetical order as per the default Notion intent.
?limit=5: limits the number of results in the response to 5.

You can add multiple query parameters to sort the data as per your use-cases.

Demo
Database: User Research Template

Request: https://rest-notion-db.herokuapp.com/page/1d595a4c3f9a4254b332587507e87267?v=43045489a1a44683b04154a85a562898&name=desc&limit=2
Response:

[{
    "completion_time": 20,
    "email": "",
    "name": "Kyle Miller",
    "rsvp": true,
    "status": "Cancelled",
    "task": ["Profile Editing"],
    "title": "Kyle Miller"
}, {
    "completion_time": 30,
    "email": "",
    "name": "Emily Cohen",
    "rsvp": false,
    "status": "Contacted",
    "task": ["Offline Mode", "Profile Editing"],
    "title": "Emily Cohen"
}]

POST data

Endpoint: /post

Send the Notion Page URL and the token_v2 cookie, in case of a private page, as request headers along with the JSON POST data.

In order to successfully POST, the request data keys should match the schema names and the values should match the schema datatypes.

Demo
Database: User Research Template

Request:
Headers

{
    "Authorization": "Bearer <TOKEN_V2>",
    "Notion-Page-Url": "<DB_PAGE_URL>",
    "Content-Type": "application/json"
}

Body

{
    "name": "Ivan Zhao",
    "task": ["Offline Mode", "Profile Editing"],
    "status": "Scheduled",
    "completion_time": 42,
    "rsvp": true
}

Response:

{
    "message": "Added data to table successfully.",
    "success": true
}

Credits

notion-py for the unofficial Notion client wrapper.

Problems?

File an issue or contact me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.