Retrieves a list of page templates that are available for creating pages within a data source. Templates define the structure and initial content for new pages.
Method
client . dataSources . listTemplates ({
data_source_id: "897e5a76-ae52-4b48-9fdf-e71f5945d1af"
})
Parameters
Identifier for the data source to list templates from.
Pagination cursor for retrieving the next page of results. If not provided, returns the first page.
The number of items to return per page. Maximum is 100. Default is 100.
Response
Returns a paginated list of data source template objects.
Array of data source template objects. Unique identifier for the template.
Display name of the template.
Description of what the template is used for.
Whether there are more templates to retrieve.
Cursor for the next page of results. null if there are no more results.
Examples
List all templates
const { Client } = require ( '@notionhq/client' )
const notion = new Client ({ auth: process . env . NOTION_TOKEN })
const response = await notion . dataSources . listTemplates ({
data_source_id: "897e5a76-ae52-4b48-9fdf-e71f5945d1af"
})
console . log ( `Found ${ response . results . length } templates` )
response . results . forEach ( template => {
console . log ( `- ${ template . name } : ${ template . description } ` )
})
let cursor = undefined
const allTemplates = []
do {
const response = await notion . dataSources . listTemplates ({
data_source_id: dataSourceId ,
start_cursor: cursor
})
allTemplates . push ( ... response . results )
cursor = response . has_more ? response . next_cursor : undefined
} while ( cursor )
console . log ( `Total templates: ${ allTemplates . length } ` )
Using the helper function
For a more convenient way to iterate through all templates, use the iterateDataSourceTemplates helper:
const { iterateDataSourceTemplates } = require ( '@notionhq/client' )
for await ( const template of iterateDataSourceTemplates ( notion , {
data_source_id: dataSourceId
})) {
console . log ( `Template: ${ template . name } ` )
}
Or collect all templates at once:
const { collectDataSourceTemplates } = require ( '@notionhq/client' )
const templates = await collectDataSourceTemplates ( notion , {
data_source_id: dataSourceId
})
console . log ( `Found ${ templates . length } templates` )
Find a specific template
const response = await notion . dataSources . listTemplates ({
data_source_id: dataSourceId
})
const meetingTemplate = response . results . find (
template => template . name . includes ( "Meeting" )
)
if ( meetingTemplate ) {
console . log ( `Found template: ${ meetingTemplate . id } ` )
}
Notes
Templates are specific to each data source and define the default structure for new pages created within that data source.