A sync pulls data from an external source into a Notion database. You can use the /sync slash command in supported coding agents (like Claude Code) to scaffold this interactively, or define it manually using worker.database() and worker.sync().
Manual implementation steps:
- Declare a database using
worker.database() with a primaryKeyProperty. - Define the database schema using
Schema helpers. - Create a pacer (optional) using
worker.pacer() to manage rate limits. - Define the sync using
worker.sync(), providing the database and an execute function that returns an object containing changes and hasMore status.
Deploy with ntn workers deploy. Syncs run automatically on a schedule (default: every 30 minutes).
import { Worker } from "@notionhq/workers";
import * as Builder from "@notionhq/workers/builder";
import * as Schema from "@notionhq/workers/schema";
const worker = new Worker();
export default worker;
const issues = worker.database("issues", {
type: "managed",
initialTitle: "Issues",
primaryKeyProperty: "Issue ID",
schema: {
properties: {
Title: Schema.title(),
"Issue ID": Schema.richText(),
},
},
});
const issueTracker = worker.pacer("issueTracker", { allowedRequests: 10, intervalMs: 1000 });
worker.sync("issuesSync", {
database: issues,
execute: async () => {
await issueTracker.wait();
const items = await fetchIssues(); // your data source
return {
changes: items.map((issue) => ({
type: "upsert" as const,
key: issue.id,
properties: {
Title: Builder.title(issue.title),
"Issue ID": Builder.richText(issue.id),
},
})),
hasMore: false,
},
},
});