Skip to main content

Notion

Notion is a commonly used workspace tool that allows teams to collaborate on notes, tasks, projects, and databases. DronaHQ supports integration very quickly with Notion, enabling users to automate workflows, fetch data, and interact with Notion databases, and much more, using multiple endpoints which users can apply directly within their apps built on DronaHQ.

Prerequisites

Notion API Key:

Obtain an API key by signing up for a Notion Developer account and creating an integration. This key is necessary to authenticate requests when using the Notion Connector.

Notion Integration - Key
Notion Integration - Key

Integrate connection with Notion Page

Once the API key is obtained, after creating an integration, there is a need to connect the pages of Notion with the integration, whose API key will be used in DronaHQ. Select the page and click on the three dots, from there under connection connect with the created integration.

Notion Page connect with Integration
Notion Page connect with Integration

Configuring API Connector in DronaHQ

  1. Create a name for your Notion connector.
  2. Enter the API key generated from your Notion Developer account into the connector setup.
  3. Once all details are provided, click Save to complete the connector configuration.
Notion Connector Configuration
Notion Connector Configuration

Supported API endpoints

ActionDescription
RetrieveBotUserInfoRetrieves information about the bot user in the workspace.
ListAllUsersLists all users in the Notion workspace.
RetrieveAUserRetrieves details of a specific user by ID.
RetrieveADatabaseFetches details of a specific database in Notion.
CreateADatabaseCreates a new database within the workspace.
UpdateADatabaseUpdates the properties of an existing database.
QueryADatabaseQueries a Notion database to retrieve filtered data.
RetrieveAPageFetches information about a specific page by ID.
RetrieveAPagePropertyItemRetrieves specific property values from a Notion page.
CreateAPageCreates a new page in a database or as a standalone page.
UpdatePagePropertiesUpdates the properties of an existing page.
SearchByTitleSearches for pages or databases by title.
RetrieveCommentsRetrieves comments associated with a page or block.
CreateCommentAdds a comment to a page or block.
RetrieveABlockFetches a specific block (content item) by ID.
RetrieveBlockChildrenRetrieves children (nested blocks) within a parent block.
DeleteABlockDeletes a specific block by ID.
UpdateABlockUpdates the content of a block.
AppendBlockChildrenAdds new children blocks to an existing parent block.

Using Notion connector

Retrieving a Database

Let's explore how to use Notion connector endpoints to fetch details from a database or page in Notion. You can call the query from data queries or trigger it through an action flow initiated by an event. First, you will need to select the environment and account whose API will be called.

Next, provide the variable details:

Here's a table outlining the variables and their descriptions for retrieving a database from Notion:

VariableDescription
Notion-VersionThe version of the Notion API you are using (e.g., 2022-06-28). This ensures compatibility with the API endpoints.
Database IDThe unique identifier for the Notion database you want to retrieve. To find this, open the database as a full page in Notion and extract the {database_id} from the URL format: https://www.notion.so/{workspace_name}/{database_id}?v={view_id}.
Retrieving a database
Retrieving a database

Additionally, you must provide permission for your integration to access the database. Ensure you share the database with your integration.

Finally, run a simple test, and this will fetch the data for the provided database ID from Notion.

Here's the revised table without the example values:

Create a Query

To create a query for a database, there are some basic components to consider, such as filtering, sorting, and the start cursor. To perform a query using the connector, select the endpoint and, after choosing the environment and account, fill in the necessary variable details.

VariableDescription
FilterWhen supplied, this limits the pages returned based on the specified filter conditions (see Notion API documentation for details).
SortsWhen supplied, this orders the results based on the provided sorting criteria (see Notion API documentation for details).
Start CursorWhen supplied, this returns a page of results starting after the provided cursor. If not supplied, this endpoint will return the first page of results.
Page SizeThis indicates the number of items from the full list that you want in the response, with a maximum limit of 100.
Querying Notion database
Querying Notion database

See below how the data changes based on the query we receive. The info with KYC checkboxes marked are fetched in an ascending order.

{
"results": [
{
"id": "1349ed43-39cd-802f-8586-dbe2ffcfc9f2",
"created_time": "2024-11-04T07:38:00.000Z",
"last_edited_time": "2024-11-04T07:39:00.000Z",
"created_by": {
"id": "750b2eba-5bbc-4d7b-a882-5fe415ce0bc3"
},
"last_edited_by": {
"id": "750b2eba-5bbc-4d7b-a882-5fe415ce0bc3"
},
"parent": {
"database_id": "12e9ed43-39cd-808d-bce9-c7b984b762dd"
},
"properties": {
"KYC": {
"checkbox": true
},
"Registration Date": {
"date": {
"start": "2024-10-29"
}
},
"ID": {
"unique_id": {
"number": 3
}
},
"Email": {
"email": "superstar@redif.com"
},
"Name": {
"title": [
{
"text": {
"content": "Puneet"
}
}
]
}
},
"url": "https://www.notion.so/Puneet-1349ed4339cd802f8586dbe2ffcfc9f2"
},
{
"id": "12f9ed43-39cd-8069-bf25-fd74e8f59c74",
"created_time": "2024-10-30T04:57:00.000Z",
"last_edited_time": "2024-11-04T07:39:00.000Z",
"created_by": {
"id": "750b2eba-5bbc-4d7b-a882-5fe415ce0bc3"
},
"last_edited_by": {
"id": "750b2eba-5bbc-4d7b-a882-5fe415ce0bc3"
},
"parent": {
"database_id": "12e9ed43-39cd-808d-bce9-c7b984b762dd"
},
"properties": {
"KYC": {
"checkbox": true
},
"Registration Date": {
"date": {
"start": "2024-10-02"
}
},
"ID": {
"unique_id": {
"number": 1
}
},
"Email": {
"email": "shibam@dronamobile.com"
},
"Name": {
"title": [
{
"text": {
"content": "Shibam"
}
}
]
}
},
"url": "https://www.notion.so/Shibam-12f9ed4339cd8069bf25fd74e8f59c74"
}
]
}

Data Transformation on Notion response

The response we received from the API is technically correct but not formatted in a way that is easy to use within a user interface. To enhance usability, we can transform the data. This can be accomplished using the Transform Response feature in a data query or by applying JavaScript code to refine the existing data.

Data Transformation
Data Transformation

JavaScript Code Example

Below is a JavaScript code snippet that takes the initial response data and transforms it into a more accessible format:

 const transformedResults = data.results.map(item => ({
id: item.id,
name: item.properties.Name.title[0].text.content,
email: item.properties.Email.email,
kycStatus: item.properties.KYC.checkbox,
registrationDate: item.properties["Registration Date"].date.start,
url: item.url
}));

data = transformedResults

Explanation of the Code:

  • Mapping: The map function is used to iterate over each item in the results array from the original data.
  • Object Construction: For each item, a new object is created that contains the relevant fields (ID, name, email, KYC status, registration date, and URL).
  • Return Value: Finally, the transformed array of objects is returned, making it easier to integrate and use in other parts of your application.