Skip to main content
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

data_source_id
string
required
Identifier for the data source to list templates from.
start_cursor
string
Pagination cursor for retrieving the next page of results. If not provided, returns the first page.
page_size
number
The number of items to return per page. Maximum is 100. Default is 100.

Response

Returns a paginated list of data source template objects.
object
string
Always "list"
results
array
Array of data source template objects.
has_more
boolean
Whether there are more templates to retrieve.
next_cursor
string | null
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}`)
})

Manual pagination

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.
Use the collectDataSourceTemplates and iterateDataSourceTemplates helper functions for easier pagination handling.

Build docs developers (and LLMs) love