Get Notion DB Page content not justDB properties

Describe the issue/error/question

How to get page content from a row in Notion DB? You know not just the properties of the table but the content inside the page

1 Like

So you’re looking for blocks :)) Check nodes below:

Any question? Do not hesitate to ask, happy to help :slight_smile:

2 Likes

That worked @Shirobachi. Two things:

A) How do I combine getAllChild Blocks? For example, inside a page there is multiple blocks like a paragraph, image, video, embed…how do I combine all in one to use for the next node ((for example publishing to twitter)?

B) How do I preserve rich text formatting in text blocks? If text is bold, output would be bold

appreciate it :grinning:

So I did not work much with blocks, but probably you will need to use function to make logic how to combine them
About formatting, notion node has special options like following:
image

But TBH notion make block hard to work with them in my opinion, so I don’t use it much

Thanks

Will give this a try and bug you with more questions :slight_smile:

1 Like

@Shirobachi getting the output data from Notion but it can’t identify the value of the relations.

Output of Notion node

[
{
"object": "page",
"id": "36533ba7-acf7-414d-8aaf-6f1884a0cf4a",
"created_time": "2022-07-02T14:55:00.000Z",
"last_edited_time": "2022-07-02T15:22:00.000Z",
"created_by": {
"object": "user",
"id": "f88037ff-f284-4448-a98e-b19e6fa623a2"
},
"last_edited_by": {
"object": "user",
"id": "f88037ff-f284-4448-a98e-b19e6fa623a2"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "9900b82b-7dbe-487c-8c57-910edbd990bd"
},
"archived": false,
"properties": {
"Channels": {
"id": "%3E%5Cjl",
"type": "relation",
"relation": [
{
"id": "6d7fadcd-50b5-4fb8-b9a1-bbeec131e12f"
},
{
"id": "57132d63-b6a4-4f92-8f42-b9026addde89"
}
]
},
"Name": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "This is my second tweet",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "This is my second tweet",
"href": null
}
]
}
},
"url": "https://www.notion.so/This-is-my-second-tweet-36533ba7acf7414d8aaf6f1884a0cf4a"
},
{
"object": "page",
"id": "54540a0e-a4c4-4302-9e6e-8cd88f1f2fa4",
"created_time": "2022-07-01T22:12:00.000Z",
"last_edited_time": "2022-07-02T15:21:00.000Z",
"created_by": {
"object": "user",
"id": "f88037ff-f284-4448-a98e-b19e6fa623a2"
},
"last_edited_by": {
"object": "user",
"id": "f88037ff-f284-4448-a98e-b19e6fa623a2"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "9900b82b-7dbe-487c-8c57-910edbd990bd"
},
"archived": false,
"properties": {
"Channels": {
"id": "%3E%5Cjl",
"type": "relation",
"relation": [
{
"id": "57132d63-b6a4-4f92-8f42-b9026addde89"
},
{
"id": "6d7fadcd-50b5-4fb8-b9a1-bbeec131e12f"
},
{
"id": "95e20361-7dff-4f35-9bf7-38dcc93ab79b"
}
]
},
"Name": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "This is my first tweet",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "This is my first tweet",
"href": null
}
]
}
},
"url": "https://www.notion.so/This-is-my-first-tweet-54540a0ea4c443029e6e8cd88f1f2fa4"
}
]

How do I map the outputted IDs of channels to the Name of their channels?

Output of channels db

[
{
"id": "95e20361-7dff-4f35-9bf7-38dcc93ab79b",
"name": "LinkedIn",
"url": "https://www.notion.so/LinkedIn-95e203617dff4f359bf738dcc93ab79b",
"property_active": true,
"property_related_to_projects_what_channel_it_s_on": [
],
"property_related_to_pooria_arab_content_types_1_channels": [
],
"property_content_hub": [
"ab0f79a6-0462-4f5f-b49e-4bd80d9ff88e"
],
"property_related_to_pooria_arab_content_types_channels": [
],
"property_total": 1,
"property_my_url": "https://www.linkedin.com/in/pooriaarab/",
"property_name": "LinkedIn"
},
{
"id": "5f385e91-48bc-4c45-ad00-ed2e1c5091b5",
"name": "Snapchat",
"url": "https://www.notion.so/Snapchat-5f385e9148bc4c45ad00ed2e1c5091b5",
"property_active": true,
"property_related_to_projects_what_channel_it_s_on": [
],
"property_related_to_pooria_arab_content_types_1_channels": [
],
"property_content_hub": [
"65095014-0d63-46ea-84c0-5ee9edb46559",
"8dd1d73e-6955-465c-a866-b4d7d9f428b0"
],
"property_related_to_pooria_arab_content_types_channels": [
],
"property_total": 2,
"property_my_url": "https://story.snapchat.com/@pooria.arab?share_id=MjkyRTgw&locale=en_CA",
"property_name": "Snapchat"
},
{
"id": "31a02c2d-6309-406c-8393-c3dc2f801a14",
"name": "Mirror.xyz",
"url": "https://www.notion.so/Mirror-xyz-31a02c2d6309406c8393c3dc2f801a14",
"property_active": true,
"property_related_to_projects_what_channel_it_s_on": [
],
"property_related_to_pooria_arab_content_types_1_channels": [
],
"property_content_hub": [
],
"property_related_to_pooria_arab_content_types_channels": [
],
"property_total": 0,
"property_my_url": "https://mirror.xyz/0xcbf1C7c40e32526f44be5Afc564Ea51666A1f6E5",
"property_name": "Mirror.xyz"
},
{
"id": "b34475b4-9c2e-448f-8a32-882988e7d6e1",
"name": "TikTok",
"url": "https://www.notion.so/TikTok-b34475b49c2e448f8a32882988e7d6e1",
"property_active": true,
"property_related_to_projects_what_channel_it_s_on": [
],
"property_related_to_pooria_arab_content_types_1_channels": [
],
"property_content_hub": [
"0f5e9878-eb37-4d08-940c-d569149aece9",
"383ceff0-9717-4fb2-a957-3a94fb44e124",
"c0d54909-fe04-46a7-a725-7442de5f1a29",
"e562df97-5f3d-4f37-a422-4c6ba7fd38d4",
"55aebe09-68c8-46a3-8289-58650a647114",
"c582850f-8429-4848-8d06-eab47eb2b2cb"
],
"property_related_to_pooria_arab_content_types_channels": [
],
"property_total": 6,
"property_my_url": "https://www.tiktok.com/@pooria.arab",
"property_name": "TikTok"
},```

Do you mind sharing this with following email (view is enough)?
[email protected],pwste.edu.pl

I am not sure, but this looks like it’s database, if so we can do it easier

@Shirobachi adding Notion page here and will add details of automation in that page

So this is relationship,

So get whole database request from n8n as notion node / database page / get All
This will also return all fields relationship one

Be sure to set good Database Name or ID, you want “Content n8n” not “Notion to Socials”

Also, you may want to add roll up props in notion if you are better in notion than n8n scripting

Just added. Please recheck.

Two main parts struggling with:

A) What data transformation to apply to get a) rich text and b) detect media?
B) Map channel ID to name to use for switching routes

Like I see this is simple text with icon, I am pretty sure you cannot retirew icon unfortunetlly but about names it should be pretty easie

So block id you can use to retriev it via notion node but it’s not necessary, check this out:

@Shirobachi tried this.

Problem with Switch, how to switch routes based on channel?

-Check if channel from relation property is equal to Twitter then take route 1

Any tips?

So you did it correct, but you have array of items and each item can holding multiple channgel so first you need to make one array of channels

see this:

Let’s explain a bit function code:
image
1: array for all channels (array of channels)
2: loop over all items (items of channels)
3: loop over channels (what is in item)
4: Adding to result array channel
5: type is channel like Twitter, text is page name

This should work cool just you might want to change text to sth else, I don’t know what should be there so if you will have problem with changing this, please let me know what should be there

Hope it’s helpful :))

1 Like

Heyy @Shirobachi thanks for the annotation and workflow!!

I’m in a pickle now :slight_smile:

Based on the Notion DB here (you can edit them over there too):

  • how to relate channels from another db to this db, join them in an array and pass on?

  • how to get markdown text to pass to socials? Bold, bullet point, links…tweet or medium post has bold text for exampl

  • how to detect image in page content AND switch for LinkedIn (post with image, without image)?

  • how to specify where new tweet (for twitter threads) begins in notion page content? Can use divider and anything after a divider would be a new tweet

  • add scheduling date

Thx :slight_smile:

Probably the easiest would be to make new property type relation :wink:

You could put text in page (related page) them use notion node / block / get child blocks and pass there relation ID. The WF what I shared had 2 arrays property_property and property_channels_n8n one of them had text like “Twitter Instagram” other IDs you could use IDs to get block.
Instead of block ID you can use page ID (from property_property prop so you will get all page blocks)

So when you will get all page’s blocks you will see sth like that

[
   {
      "object":"block",
      "parent_id":"493113b962f943609e85f524565346f4",
      "id":"725ecabf-9ac6-48d0-9477-3843a0aa2f40",
      "parent":{
         "type":"page_id",
         "page_id":"493113b9-62f9-4360-9e85-f524565346f4"
      },
      "created_time":"2022-07-03T14:00:00.000Z",
      "last_edited_time":"2022-07-03T14:00:00.000Z",
      "created_by":{
         "object":"user",
         "id":"2c9470b7-aa7f-4124-8fed-5babbc806ba2"
      },
      "last_edited_by":{
         "object":"user",
         "id":"2c9470b7-aa7f-4124-8fed-5babbc806ba2"
      },
      "has_children":false,
      "archived":false,
      "type":"image",
      "image":{
         "caption":[
            
         ],
         "type":"file",
         "file":{
            "url":"https://s3.us-west-2.amazonaws.com/secure.notion-static.com/c7c444b1-04a8-42f4-a94a-4d16793eb7aa/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220703%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220703T140122Z&X-Amz-Expires=3600&X-Amz-Signature=c872ceda5515c221633e968f9cb1b4fef941f631e73563544e848b54bcae33ea&X-Amz-SignedHeaders=host&x-id=GetObject",
            "expiry_time":"2022-07-03T15:01:22.028Z"
         }
      }
   }
]

In this case, we have file and link to them. I do not see way to see difference b/w file like PDF and image, so I hope you don’t expect to use other files that image. If so, you can detect image via if statement "type": "file"

Sorry, I don’t understand what you mean ;/

So if you mean schedule tweet creation like I see is no way to do this in Twitter API, so I would add WF trigger as every minute or 5 minutes, and each time check if notion prop schedule if grater than now and only if it’s post twitter
To use time manipulation I would use moment JS, if you wish to use it you need to:

  • add to docker variable this: - NODE_FUNCTION_ALLOW_EXTERNAL=moment
  • add to function node where you wish to use this const moment = require("moment")
  • and be aware that moment is deprecated and is NOT recommended to use it anymore ;D

Ending disclaimer, I use notion node a lot, but not blocks, I feel that notion made an awful job with that part of them API. When I need, I always try to use properties, so if I were you, I would try to add image as property file or URL. But of course that’s your decision, and I’ll be happy to help anyway ;))

Warm Simon :wink:

Thanks @Shirobachi for the detailed responses.

I’m learning a lot about n8n and JS expressions in post :slight_smile:

Though, the function doesn’t work:

This is the 2 Notion DB here and am using the relation property as you suggested.

That’s weird, work on my instance ;/ But I see you use as input block, so maybe this probay make problem, I made that function for database output as I remember, possible needs to be changed some things because structure is different ;/

Hmm. Most likely because it says item line3 not found. What do you recommend?

I don’t know TBH. I see that items is defined… what’s in details?

That’s the error I get.

The function doesn’t detect the items I believe and this is the glue for the other parts. Guess if this works the rest is based on this