Install
openclaw skills install sync-data-notionUse when (1) user says 'Sync data to Notion database'. (2) user provides a CSV or JSON file and asks to sync it into a Notion database. (3) user wants to keep a Notion database in sync with an external data source on a recurring basis.
openclaw skills install sync-data-notionThis skill handles bidirectional data synchronization between external sources (CSV, JSON, REST API) and a target Notion database. It is NOT a one-shot import — it manages consistency, conflict detection, incremental updates, and partial failure handling.
Key responsibilities:
NOTION_API_KEY environment variable (never hardcode tokens)GET /databases/{id}) to validate property types before writing/sync-data-notion --fullFull sync mode. Retrieves all records from the external source, compares with all existing Notion records (by ID or configured key field), and creates/updates as needed.
When to use: Initial sync, or when you suspect records have been modified outside the sync relationship.
/sync-data-notion --incrementalIncremental sync. Only syncs records where updated_at (or configured timestamp field) is newer than the last sync timestamp stored in ~/.sync_notion_last_run/{database_id}.json.
When to use: Recurring scheduled syncs. Requires --last-run to be set or a previous run timestamp to exist.
/sync-data-notion --dry-runPreview mode. Shows exactly what would change — new records, updated records, deleted records — without making any API calls that modify data.
When to use: Before a live sync, to let the user review and approve changes.
/sync-data-notion --reverseNotion → External export. Reads records from a Notion database and writes them to the external system. Requires --target to specify the destination format (CSV/JSON/REST endpoint).
When to use: When the external system is the primary store and Notion is used for review/editing.
Read the provided data source:
csv.DictReader, validate headers against the Notion database schemanext_cursorIf malformed, stop and report:
Sync input is malformed at row {N}: missing required field "{field}".
Expected: {field_type} (from Notion database schema).
Received: {actual_value} (type {actual_type}).
GET https://api.notion.com/v1/databases/{database_id}
Authorization: Bearer {NOTION_API_KEY}
Notion-Version: 2022-06-28
Parse properties to build a schema map:
title → write via title array (required)rich_text → write via rich_text array of text objectsnumber → write via number (must be float or null, not string)checkbox → write via booleanselect → write via select object {name: value}multi_select → write via multi_select array of {name: value} objectsdate → write via date object {start: ISO8601}url → write via url stringemail → write via email stringphone_number → write via phone_number stringIf a Notion property type is not supported (e.g., formula, relation, rollup), skip that property and log a warning.
Map source fields to Notion properties. Show the user a table before proceeding:
Source field → Notion property → Type
─────────────────────────────────────────────────
email → Email → email
name → Title → title
status → Status → select
tags → Tags → multi_select
created_at → Created Date → date
If a required Notion property has no mapping:
title: stop — "Missing required title field in source data"nullPOST https://api.notion.com/v1/databases/{database_id}/query
{
"page_size": 100,
"start_cursor": "..." // paginate through all pages
}
Build a lookup map: {external_id or configured key field → Notion page_id} for change detection.
Create new record:
POST https://api.notion.com/v1/pages
{
"parent": {"database_id": "{database_id}"},
"properties": { /* mapped properties */ }
}
Update existing record:
PATCH https://api.notion.com/v1/pages/{page_id}
{
"properties": { /* mapped properties */ }
}
Use bulk endpoints where available (up to 10 pages per batch for creates via POST /v1/pages with individual objects in children — actually Notion API only supports 1 page per request, so serialize writes).
Track per-record outcomes:
created_count: pages successfully createdupdated_count: pages successfully updatedfailed_count: records that failed with reasonskipped_count: records skipped (no changes detected in incremental sync)On 429 (rate limit): Wait Retry-After header seconds, retry up to 3 times.
On 400 (validation error): Log the specific property error, skip the record.
On 401/403: Stop immediately — "Authentication failed — check NOTION_API_KEY environment variable."
After sync completes, query a sample of created/updated records to confirm they exist:
GET https://api.notion.com/v1/pages/{page_id}
If records missing after write, retry up to 2 times, then flag for manual review.
Return structured summary:
{
"created": 47,
"updated": 12,
"failed": 3,
"skipped": 5,
"field_mapping": {"email": "Email", "name": "Title", ...},
"failures": [
{"record_id": "abc123", "reason": "Invalid email format"},
{"record_id": "def456", "reason": "Notion property 'Status' does not have option 'Pending'"}
]
}
os.getenv("NOTION_API_KEY")--dry-run to preview changes--auto-approve is set)formula, relation, rollup, file, verified are read-only in Notion APIexternal_id) for traceability~/.sync_notion_last_run/{database_id}.json for incremental syncs| Criterion | Minimum | Ideal |
|---|---|---|
| Records synced | 100% of valid input records | 100% including edge cases (nulls, special chars, multi-line text) |
| Field mapping coverage | 100% — every source field mapped | Documented + user-confirmed mapping before sync |
| Failures reported | 100% with per-record reason | Root cause + suggested fix per failure |
| Dry-run accuracy | Preview shows exact creates/updates | Zero unexpected changes in live sync |
| Authentication | Uses env vars, no tokens in code | Token auto-refresh on 401 with re-auth flow |
| Rate limit handling | 429 caught, 3 retries with backoff | Adaptive backoff based on Retry-After header |
| Property type validation | Validates before write | Schema validated at sync start, not per-record |
Every sync execution must return a structured JSON summary. A good output is one where all fields are mapped, every failure has a reason, and the field mapping table was shown before changes were made.
| Scenario | Bad | Good |
|---|---|---|
| Missing field | Silently skips row, reports "Sync complete" | Reports "Skipped row 47: required field 'email' missing — Notion title cannot be empty" |
| Auth failure | Retries with same token, fails silently | Stops immediately with "Authentication failed — check NOTION_API_KEY env var is set and valid" |
| Rate limited | Ignores 429, continues, misses records | Pauses 30s (Retry-After), retries 3x, reports "Rate limited at batch 5 — paused 30s, retrying" |
| Partial failure | Reports "Sync complete" with all success | Reports "Sync partial: 47 created, 2 failed (see failures array for details)" |
| Dry-run vs live | No distinction in output format | Dry-run returns same JSON structure with preview: true and no page IDs assigned |
| Field mapping | Defaults silently to "field not mapped" | Shows full mapping table with arrow notation email -> Email (email type) before sync |
| Multi-select | Converts array to string, stores "tag1,tag2" in select | Maps to multi_select array: [{"name": "tag1"}, {"name": "tag2"}] |
| Date field | Stores date string as rich_text | Sends as {"date": {"start": "2024-01-15"}} — ISO8601 format |
| Null handling | Skips field entirely | Sends null for optional fields; skips only if field absent from source |