How to read block mentions with Notion API (Python)?

120 Views Asked by At

EDIT: This is not supported yet (Notion-Version: 2022-06-28)


I'm setting up an integration using Python 3 to reformat some previously typed out pages but I noticed I wasn't able to see text when I copy/paste a link to another block. The parent page has been added to my integration, but I just get empty rich text.

Everything else reads fine so far: page mentions, user mentions, but not block mentions--is this just not supported yet?

I'm using a GET request to "https://api.notion.com/v1/blocks/{block_id}" with headers:

{
    "Authorization": f"Bearer {NOTION_SECRET}",
    "Content-Type": "application/json",
    "Notion-Version": "2022-06-28",
}

Here's what it appears as in Notion: Picture of block mention after copy/pasting with "Mention block" option

The line I want to mention comes back as this:

{
    "archived": False,
    "bulleted_list_item": {
        "color": "default",
        "rich_text": [
            {
                "annotations": {
                    "bold": False,
                    "code": False,
                    "color": "default",
                    "italic": False,
                    "strikethrough": False,
                    "underline": False,
                },
                "href": None,
                "plain_text": "This is my test block " "I want to mention it later",
                "text": {
                    "content": "This is my test " "block I want to " "mention it later",
                    "link": None,
                },
                "type": "text",
            }
        ],
    },
    "has_children": False,
    "object": "block",
    "type": "bulleted_list_item",
    # etc.
}

But the following line with the mention comes back as:

{
    "archived": False,
    "bulleted_list_item": {
        "color": "default",
        "rich_text": [
            {
                "annotations": {
                    "bold": False,
                    "code": False,
                    "color": "default",
                    "italic": False,
                    "strikethrough": False,
                    "underline": False,
                },
                "href": None,
                "plain_text": "In this line, I will "
                "mention the block before "
                "by right-clicking, using "
                "the “Copy link to block” "
                "action, then pasting and "
                "selecting the “Mention "
                "block” action: ",
                "text": {
                    "content": "In this line, I "
                    "will mention the "
                    "block before by "
                    "right-clicking, "
                    "using the “Copy "
                    "link to block” "
                    "action, then "
                    "pasting and "
                    "selecting the "
                    "“Mention block” "
                    "action: ",
                    "link": None,
                },
                "type": "text",
            }
        ],
    },
    "has_children": False,
    "object": "block",
    "type": "bulleted_list_item",
    # etc.
}

or simply on its own:


{
    "archived": False,
    "bulleted_list_item": {
        "color": "default",
        "rich_text": [
            {
                "annotations": {
                    "bold": False,
                    "code": False,
                    "color": "default",
                    "italic": False,
                    "strikethrough": False,
                    "underline": False,
                },
                "href": None,
                "plain_text": " ",
                "text": {"content": " ", "link": None},
                "type": "text",
            }
        ],
    },
    "has_children": False,
    "object": "block",
    "type": "bulleted_list_item",
    # etc.
}
1

There are 1 best solutions below

0
On

Turns out this simply isn't supported yet. Got verification from the Notion support email and I was referred to this section of the Notion docs where "block mentions" are not included yet.

https://developers.notion.com/reference/rich-text#mention

Hopefully one day!