Chapter 75 – CRUD Notion Page Content Using Notion API & Python

ChatGPT is super blink recently because it transforms our life and work style upside down. Likey I am incline to use OpenAI API GPT3 and GPT 3.5 API as it can totally automate my life and off load repetitive work that wastes time but is critical. Using both of them is just like eating a piece of buttery and marbling rich Wagyu beef.

In fact, we never only have one option. Between API and AI chatbot, Notion AI which is using Anthropic’s Claude generative AI model can perfectly provide you semi-auto AI experience with its AI writing and API capability. Although it’s not as crunch as GPT 3, it impresses users with clear, thin and straight using experience.

In this piece, I would walk you through how to retrieve Notion AI content from Notion private page, and update new content using Notion API.

ChatGPT is super blink recently because it transforms our life and work style upside down. Likey I am incline to use OpenAI API GPT3 and GPT 3.5 API as it can totally automate my life and off load repetitive work that wastes time but is critical. Using both of them is just like eating a piece of buttery and marbling rich Wagyu beef.

In fact, we never only have one option. Between API and AI chatbot, Notion AI which is using Anthropic’s Claude generative AI model can perfectly provide you semi-auto AI experience with its AI writing and API capability. Although it’s not as crunch as GPT 3, it impresses users with clear, thin and straight using experience.

In this piece, I would walk you through how to retrieve Notion AI content from Notion private page, and update new content using Notion API.

Tables of Content: CRUD Notion Page Content Using Notion API

New App and Notion API Key Creation

Notion provides a free trial with 20 requests of generative AI. Compared to other AI platform like OpenAI, Notion’s strength is onsite content and database management and mainly is relevant to writing, translation, summarization. It has a monthly plan which is priced at 10 dollars. Either free or monthly plan can let users create an App, which allows you to connect your App with Notion. But from my perspective, it’s not worth it to join if only using API without Notion AI. It’s because standing on a database and content hub management, available options out there are very much and frankly it’s much developer-convenient.

The API key is available in my connection management page and there are two options you can set for your API, which is internal and public. For this case, we can select the internal purpose.

Once created, please create a new parent Page in advance and connect the page with your App. Basically it’s ready and we can start writing the script.

Fundamental API authentication and header settings in Python

Basically there are two main Notion API endpoints we will use in CRUD page content. These are as follows:

https://api.notion.com/v1/pages

https://api.notion.com/v1/blocks/

Then, we need to set a header by either creating a class or not, that depends on your App situation. Whatever case your is, this is a fundamental header you need to set up

   headers = {

       "accept": "application/json",

       "Notion-Version": "2022-06-28",

       "content-type": "application/json",

       "Authorization": "your Notion API Key"

   }

CRUD – Create a Notion Page using Notion API

Creating a new page that is a child of an existing page just requires the title component. The title is the only valid property in the properties body param.

If you are interested in the full script of creating a new page, please subscribe to us with leaving a message “ Chapter 75 + notion API”

CRUD – Retrieve Notion Private Page Block Content using Notion API

Getting the page block content requires two main components, which are the parent page ID and json library.

First thing first, we can either use a search endpoint to get the page ID or directly copy and input the ID into this endpoint path.

url = "https://api.notion.com/v1/blocks/" + pageID + "/children"

Then, using request to call the endpoint data and it would return JSON data format so we need to add json() to interpret it.

response = requests.get(url, headers=headers).json()['results']

Last but not least, the response format would be something like this below, which looks a little bit long but it’s not complex.

{

    "object": "block",

    "id": "c02fc1d3-db8b-45c5-a222-27595b15aea7",

    "parent": {

        "type": "page_id",

        "page_id": "59833787-2cf9-4fdf-8782-e53db20768a5"

    },

    "created_time": "2022-03-01T19:05:00.000Z",

    "last_edited_time": "2022-07-06T19:41:00.000Z",

    "created_by": {

        "object": "user",

        "id": "ee5f0f84-409a-440f-983a-a5315961c6e4"

    },

    "last_edited_by": {

        "object": "user",

        "id": "ee5f0f84-409a-440f-983a-a5315961c6e4"

    },

    "has_children": false,

    "archived": false,

    "type": "heading_2",

    "heading_2": {

        "rich_text": [

            {

                "type": "text",

                "text": {

                    "content": "Lacinato kale",

                    "link": null

                },

                "annotations": {

                    "bold": false,

                    "italic": false,

                    "strikethrough": false,

                    "underline": false,

                    "code": false,

                    "color": "green"

                },

                "plain_text": "Lacinato kale",

                "href": null

            }

        ],

        "color": "default",

    "is_toggleable": false

    }

}

CRUD – Update Notion Private Page Block Content using Notion API

As well as Notion page content retrieving, updating also uses the same API endpoint path. Instead of using ‘get’ method, here needs a patch method to update specific page block content.

   response = requests.request(

       "PATCH",

       url,

       headers=headers,

       json={"children": [text_block]}

   )

According to specific content type and format, we also need a JSON data with the key children. Here is a sample as follows:

   text_block = {

       "type": "paragraph",

       "paragraph": {

           "rich_text":[{

               "type": "text",

               "text": {

                   "content": textBook,

                   "link": None

               }

           }]

       }

   }

CRUD – Delete Notion 

In Notion, deleting a Notion page is called archive. To archive a page via the API, send an Update page request with the archived body param set to true. To restore a page, set archived to false.

If you are interested in the full script of creating a new page, please subscribe to us with leaving a message “ Chapter 75 + notion API”

Full Python Script of Retrieve and Update Using Notion API

If you are interested in Chapter 75 – CRUD Notion Page Content Using Notion API & Python, please subscribe to our newsletter by adding the message ‘Chapter 75 + notion api’. We would send you the script immediately to your mailbox.

I hope you enjoy reading Chapter 75 – CRUD Notion Page Content Using Notion API & Python. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

FAQ:

Q1: What is Notion Page Content CRUD?

A: Notion Page Content CRUD is a brand product that allows users to create, read, update, and delete content on Notion pages.

Q2: How does Notion Page Content CRUD work?

A: Notion Page Content CRUD provides a set of APIs that developers can use to interact with Notion pages and perform CRUD operations on their content.

Q3: What platforms does Notion Page Content CRUD support?

A: Notion Page Content CRUD is designed to work with any platform that supports API integration, including web, mobile, and desktop applications.

Q4: Can I use Notion Page Content CRUD for personal use?

A: Yes, Notion Page Content CRUD can be used by individuals for personal use to manage their Notion pages and content.

Q5: Is Notion Page Content CRUD suitable for businesses?

A: Absolutely! Notion Page Content CRUD is ideal for businesses of all sizes that want to streamline their content management process and enhance collaboration on Notion pages.

Q6: Are there any limitations on the number of pages or content I can manage with Notion Page Content CRUD?

A: Notion Page Content CRUD does not impose any limitations on the number of pages or content you can handle. You have complete flexibility and control.

Q7: Can I integrate Notion Page Content CRUD with my existing tools or systems?

A: Yes, Notion Page Content CRUD offers seamless integration capabilities, allowing you to connect it with your existing tools and systems, such as project management software or customer relationship management (CRM) systems.

Q8: Do I need coding knowledge to use Notion Page Content CRUD?

A: While some coding knowledge can be helpful, Notion Page Content CRUD provides comprehensive documentation and guides to assist users in implementing and utilizing the APIs without extensive coding experience.

Q9: Is there customer support available for Notion Page Content CRUD?

A: Yes, we offer customer support for Notion Page Content CRUD. Our team is available to assist you with any questions or issues you may encounter.

Q10: How do I get started with Notion Page Content CRUD?

A: To get started with Notion Page Content CRUD, simply sign up for an account on our website and follow the setup instructions provided. You’ll be up and running in no time!