Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rudifa/go-notion
Learning to retrieve data from a Notion database using go language
https://github.com/rudifa/go-notion
Last synced: 24 days ago
JSON representation
Learning to retrieve data from a Notion database using go language
- Host: GitHub
- URL: https://github.com/rudifa/go-notion
- Owner: rudifa
- License: mit
- Created: 2023-04-22T18:15:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-05T19:07:10.000Z (over 1 year ago)
- Last Synced: 2024-10-06T01:41:19.615Z (about 1 month ago)
- Language: Go
- Size: 7.72 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Notion API access using go language
Demo based on [Getting started with the Notion API JavaScript SDK](https://dev.to/craigaholliday/getting-started-with-the-notion-api-javascript-sdk-c50) -> `retrieveDatabase`
## Notion setup
In the target Notion workspace - Settings - Connections - Develop and manage integrations:
- create a new Integration, give it a name
- copy the `Internal Integration Token` to the local file .envIn the target Notion workspace - target page:
- ... menu - Connections: add a connection to the named Integration
- Share - Copy link: copy the url link and paste into a text editor
- extract the first 32-character `UUID` and paste it into the local .env file## Setup
**Requires** a file named `.env` in the project directory, containing the keys from Notion
```
NOTION_INTEGRATION_TOKEN=secret_n3w...ZWq # 56 chars `Internal Integration Token`
NOTION_DATABASE_ID=ef7...b44 # 32 chars `UUID`
# NOTION_DATABASE_ID=... # comment out unused tokens
```To change the target Notion workspace or the database, edit your `.env` file
adding the new tokens and commenting out or removing the old tokens.## Run dev
`go run go-notion.go` # build an in-memory executable and run it
## Build and run
`go build go-notion.go` # build the executable `go-notion` in the project directory.
`./go-notion` # run the executable
## Test
`go test ./...` # run unit tests
## Usage
```
Usage:
go-notion [command]Available Commands:
help Help about any command
query Query the database
retrieve Retrieve data from the databaseFlags:
-h, --help help for go-notionUse "go-notion [command] --help" for more information about a command.
```## Notes
This version supports command prefix matching (it suffices to enter the leading letters of a command).
This version of `go-notion` runs the functions `QueryDatabase`and `RetrieveDatabase`
with tokens specified in the `.env` file (required)
and prints to stdout the received json string.`query` retrieves successfully a Notion table containing 796 entries (117614 lines, 4.2MB).
This program uses no Notion specific libraries.
## Notion API docs
[Retrieve a database](https://developers.notion.com/reference/retrieve-a-database) -> `RetrieveDatabase`
[Query a database](https://developers.notion.com/reference/post-database-query)-> `QueryDatabase`