Notion Database

Query a public Notion database, supporting both basic information and SQL query.

This widget supports multiple actions. For a more comprehensive understanding of its functionality, we recommend reviewing the following documentation carefully.

You need to pass both the action and other input parameters of the chosen action to your module_config

Try it in the Widget Center

Click this url to try this widget and copy the Pro Config template.

Usage

Query the Whole Database

action query_all

Input Parameters

NameTypeDescriptionDefaultRequired

url

string

URL of the public database

action

string

The action you want to perform

query_all

Output Parameters

NameTypeDescriptionFile Type

data

array

The returned database in list

Output Example

{
  "data": [
    {
      "Age": "15",
      "Name": "Jack",
      "Password": "password1",
      "Phone Number": "13033331111"
    },
    {
      "Age": "34",
      "Name": "Taylor",
      "Password": "password2",
      "Phone Number": "13100001111"
    },
    {
      "Age": "17",
      "Name": "Harry",
      "Password": "password3",
      "Phone Number": "13888883333"
    },
    {
      "Age": "43",
      "Name": "Sherlock",
      "Password": "password4",
      "Phone Number": "15909098787"
    }
  ]
}

Obtain the Column Names

action query_schema

Input Parameters

NameTypeDescriptionDefaultRequired

url

string

URL of the public database

action

string

The action you want to perform

query_schema

Output Parameters

NameTypeDescriptionFile Type

data

array

The column names of the database

Output Example

{
  "data": [
    "Phone Number",
    "Age",
    "Password",
    "Name"
  ]
}

Query All Values of a Specific Column

action query_column

Input Parameters

NameTypeDescriptionDefaultRequired

url

string

URL of the public database

action

string

The action you want to perform

query_column

column_name

string

Colume name to query

Output Parameters

NameTypeDescriptionFile Type

data

array

The values under a specific column

Output Example

{
  "data": [
    "Jack",
    "Taylor",
    "Harry",
    "Sherlock"
  ]
}

Query The Database with SQL

action query_sql

This action provides an advanced query with SQL. The table name is defined as DATA

Input Parameters

NameTypeDescriptionDefaultRequired

url

string

URL of the public database

action

string

The action you want to perform

query_sql

sql_str

string

SQL string to query, please use it like 'SELECT * FROM database'

SELECT * FROM DATA WHERE Age < 18

Output Parameters

NameTypeDescriptionFile Type

data

array

The query results of the public Notion database

Output Example

{
  "data": [
    {
      "Age": "15",
      "Name": "Jack",
      "Password": "password1",
      "Phone Number": "13033331111"
    },
    {
      "Age": "17",
      "Name": "Harry",
      "Password": "password3",
      "Phone Number": "13888883333"
    }
  ]
}

Add Rows

action add_rows

This action provides a interface to add rows to a public notion database

Input Parameters

NameTypeDescriptionDefaultRequired

url

string

URL of the public database

action

string

The action you want to perform

add_rows

rows_info

string

Rows information to add

[{}]

Output Parameters

NameTypeDescriptionFile Type

data

array

The query results of the public Notion database

Output Example

{
  "data": [
    {
      "result": "success"
    }
  ]
}

Detailed Guidelines

In notion, we can type /database to create a database. Then click the open as full page as below:

click the share button and copy the url to feed into your Notion Database widget:

If you want to add information to the notion, you can use theadd_rowsaction. The json format should follow the format like

[{"Name": "Jack", "Phone Number": "13033331111", "Password": "password1"}]

However, f you want to use it in pro config use values of variables, please note that the"symbols should be escaped like

[{\"Name\": \"{{name}}\", \"Phone Number\": \"{{phone_number}}\", \"Password\": \"{{password}}\"}]

The sturcture of proconfig may looks like

{
  "id": "notion_add_rows_template",
  "initial": "home_state",
  "states": {
    "home_state": {
      "inputs": {
        "url": {
          "type": "text",
          "description":"URL of the public database",
          "user_input": true
        },
        "name": {
          "type": "text",
          "user_input": true
        },
        "phone_number": {
          "type": "text",
          "user_input": true
        },
        "password": {
          "type": "text",
          "user_input": true
        }
      },
      "tasks": [
        {
          "name": "any_module_example_task",
          "module_type": "AnyWidgetModule",
          "module_config": {
            "widget_id": "1782389035948912640",            
            "url":"{{url}}", // this field will received value from user input
            "action":"add_rows", // The action you want to perform
            "rows_info":"[{\"Name\": \"{{name}}\", \"Phone Number\": \"{{phone_number}}\", \"Password\": \"{{password}}\"}]", // Rows information to add
            "output_name": "result"
          }
        }
      ],
      "render": {
        "text": "{{JSON.stringify(result)}}", // this widget will output a map, you can first run it and know what its type is.
        "buttons": [
          {
            "content":"Try Again",
            "description":"",
            "on_click":"try_again"
          }
        ]
      },
      "transitions": {
        "try_again": "home_state"
      }
    }
  }
}

Last updated