I’m trying to set up an automated system for my daily journaling in Notion. The title format I want is ‘Daily Journal @today’. Here’s what I’ve got so far in my code:
const pageData = {
parent: { database_id: myDatabaseId },
properties: {
title: {
title: [
{
text: {
content: 'Daily Journal' // Need help adding @today here
}
}
]
},
date: new Date().toISOString()
}
};
I’m stuck on how to add the @today mention in the title. Does anyone know the correct syntax or method to include mention tags when creating a page title through the API? Thanks for any help!
I’ve encountered a similar challenge with Notion’s API. The key is to use a combination of ‘text’ and ‘mention’ properties in your title array. Here’s a modified version of your code that should work:
This approach creates a title with ‘Daily Journal’ as text, followed by the @today mention. The mention uses the current date, which Notion will interpret as ‘today’. Remember to include a space after ‘Journal’ in the text content for proper formatting.
As someone who’s been using Notion’s API extensively for automating workflows, I can confirm that handling mentions in titles can be tricky. The solutions provided by others are on point, but I’d like to add a bit more context.
When working with the Notion API, it’s crucial to understand that mentions are treated as separate entities from regular text. This is why you need to combine both text and mention objects in your title array.
One thing to keep in mind is that the @today mention will always display the current date when viewed, not the date when the page was created. If you want to ‘freeze’ the date, you might consider using a separate date property instead.
Also, don’t forget to handle potential errors. The API can sometimes be finicky, so wrapping your requests in try-catch blocks is a good practice. This has saved me countless headaches during development.
Lastly, if you’re doing this frequently, consider creating a helper function to generate these title structures. It’ll make your code more readable and maintainable in the long run.