> For the complete documentation index, see [llms.txt](https://myshell-wiki.gitbook.io/proconfig-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://myshell-wiki.gitbook.io/proconfig-tutorial/api-reference/widgets/23-notion-database.md).

# Notion Database

{% hint style="info" %}
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`
{% endhint %}

## Try it in the Widget Center

Click this [url](https://app.myshell.ai/robot-workshop/widget/1782389035948912640) to try this widget and copy the Pro Config template.

## Usage

### Query the Whole Database

<mark style="color:green;">`action`</mark> `query_all`

**Input Parameters**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td><code>string</code></td><td>URL of the public database</td><td><a href="https://myshellai.notion.site/7f0dc468d15a4810ac9a1caa7799da7a?v=a8830827ab584b70b939015d9e76bbb2&#x26;pvs=4">default_url</a></td><td>true</td></tr><tr><td>action</td><td><code>string</code></td><td>The action you want to perform</td><td>query_all</td><td>true</td></tr></tbody></table>

**Output Parameters**

| Name | Type    | Description                   | File Type |
| ---- | ------- | ----------------------------- | --------- |
| data | `array` | The returned database in list |           |

**Output Example**

{% tabs %}
{% tab title="success" %}
{% code fullWidth="false" %}

```json
{
  "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"
    }
  ]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Obtain the Column Names

<mark style="color:green;">`action`</mark> `query_schema`

**Input Parameters**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td><code>string</code></td><td>URL of the public database</td><td><a href="https://myshellai.notion.site/7f0dc468d15a4810ac9a1caa7799da7a?v=a8830827ab584b70b939015d9e76bbb2&#x26;pvs=4">default_url</a></td><td>true</td></tr><tr><td>action</td><td><code>string</code></td><td>The action you want to perform</td><td>query_schema</td><td>true</td></tr></tbody></table>

**Output Parameters**

| Name | Type    | Description                      | File Type |
| ---- | ------- | -------------------------------- | --------- |
| data | `array` | The column names of the database |           |

**Output Example**

{% tabs %}
{% tab title="success" %}
{% code fullWidth="false" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

### Query All Values of a Specific Column

<mark style="color:green;">`action`</mark> `query_column`

**Input Parameters**

<table><thead><tr><th>Name</th><th>Type</th><th>Description</th><th>Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td><code>string</code></td><td>URL of the public database</td><td><a href="https://myshellai.notion.site/7f0dc468d15a4810ac9a1caa7799da7a?v=a8830827ab584b70b939015d9e76bbb2&#x26;pvs=4">default_url</a></td><td>true</td></tr><tr><td>action</td><td><code>string</code></td><td>The action you want to perform</td><td>query_column</td><td>true</td></tr><tr><td>column_name</td><td><code>string</code></td><td>Colume name to query</td><td></td><td>true</td></tr></tbody></table>

**Output Parameters**

| Name | Type    | Description                        | File Type |
| ---- | ------- | ---------------------------------- | --------- |
| data | `array` | The values under a specific column |           |

**Output Example**

{% tabs %}
{% tab title="success" %}
{% code fullWidth="false" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

### Query The Database with SQL

<mark style="color:green;">`action`</mark> `query_sql`

This action provides an advanced query with SQL. The table name is defined as `DATA`&#x20;

**Input Parameters**

<table><thead><tr><th>Name</th><th width="40">Type</th><th>Description</th><th>Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td><code>string</code></td><td>URL of the public database</td><td><a href="https://myshellai.notion.site/7f0dc468d15a4810ac9a1caa7799da7a?v=a8830827ab584b70b939015d9e76bbb2&#x26;pvs=4">default_url</a></td><td>true</td></tr><tr><td>action</td><td><code>string</code></td><td>The action you want to perform</td><td>query_sql</td><td>true</td></tr><tr><td>sql_str</td><td><code>string</code></td><td>SQL string to query, please use it like 'SELECT * FROM database'</td><td>SELECT * FROM DATA WHERE Age &#x3C; 18</td><td>true</td></tr></tbody></table>

**Output Parameters**

| Name | Type    | Description                                     | File Type |
| ---- | ------- | ----------------------------------------------- | --------- |
| data | `array` | The query results of the public Notion database |           |

**Output Example**

{% tabs %}
{% tab title="success" %}
{% code fullWidth="false" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

### Add Rows

<mark style="color:green;">`action`</mark> `add_rows`

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

**Input Parameters**

<table><thead><tr><th>Name</th><th width="40">Type</th><th>Description</th><th>Default</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td><code>string</code></td><td>URL of the public database</td><td><a href="https://myshellai.notion.site/7f0dc468d15a4810ac9a1caa7799da7a?v=a8830827ab584b70b939015d9e76bbb2&#x26;pvs=4">default_url</a></td><td>true</td></tr><tr><td>action</td><td><code>string</code></td><td>The action you want to perform</td><td>add_rows</td><td>true</td></tr><tr><td>rows_info</td><td><code>string</code></td><td>Rows information to add</td><td>[{}]</td><td>true</td></tr></tbody></table>

**Output Parameters**

| Name | Type    | Description                                     | File Type |
| ---- | ------- | ----------------------------------------------- | --------- |
| data | `array` | The query results of the public Notion database |           |

**Output Example**

{% tabs %}
{% tab title="success" %}
{% code fullWidth="false" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

## Detailed Guidelines

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

<figure><img src="/files/RfhaJ7BfHCIeOvzgVmLl" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/sz8UuWP42uonRmHYjs7R" alt=""><figcaption></figcaption></figure>

If you want to add information to the notion, you can use the`add_rows`action. 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

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

The sturcture of proconfig may looks like

```json
{
  "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"
      }
    }
  }
}
```
