You’re receiving a 400 error with the message “Unsaved transactions: Unrecognized error” from the Notion API when trying to add new entries to a database. This error persists even after reverting code changes, suggesting the problem lies outside your application code and might be related to the Notion API’s state or handling of concurrent requests.
Understanding the “Why” (The Root Cause):
The “Unsaved transactions: Unrecognized error” message usually indicates a problem with how Notion handles concurrent database writes or internal state issues within the API itself. It’s not necessarily a coding error in your app. Several factors can contribute to this:
Concurrent Requests: Multiple requests to the API, perhaps from different parts of your application or even from separate browser tabs/windows accessing your Notion workspace, can lead to conflicts and leave transactions in an inconsistent state.
API Rate Limits: Exceeding Notion’s API rate limits can cause requests to fail or be delayed, resulting in the “unsaved transactions” error.
Notion API Internal State: Occasionally, the Notion API itself can experience temporary issues or internal inconsistencies that lead to this error. These issues are usually transient and resolve themselves, but they can cause temporary disruptions.
Conflicting Data: If your database contains formula properties or other dependencies, incorrect or incomplete data could trigger validation errors that cascade into this “unsaved transactions” problem.
Step-by-Step Guide:
Identify and Resolve Concurrent Requests: The most likely culprit is concurrent requests to the Notion API.
Thoroughly review your application’s code: Ensure that you are not making multiple simultaneous requests to the same database. Implement proper error handling and potentially queuing mechanisms to manage requests sequentially.
Close all Notion-related browser tabs and windows: Ensure no other instances of your application are interacting with the Notion API. Clear your browser’s cache and local storage, just in case stale tokens or cached data are causing conflicts.
Check for background processes: If you’re running any development servers or background tasks, ensure they are not making concurrent API calls.
Verify API Integration Token and Permissions:
Regenerate your Integration Token: In your Notion workspace, regenerate your integration token. Corrupted tokens can lead to unexpected API behavior.
Check Token Permissions: Confirm that your integration token has the necessary permissions to write to your database.
Examine Your API Requests:
Add Comprehensive Logging: Implement detailed logging to record all API requests, including timestamps, headers, and responses. This will help diagnose the sequence of events leading to the error.
Inspect Request Headers: Ensure your requests include the correct content-type and Notion-Version headers. Improperly formatted requests can trigger validation errors.
Test with a New Database:
Create a Fresh Test Database: Create a completely new Notion database and point your API calls to this new test database. If the problem disappears, the issue is specifically related to your original database’s state.
Implement Error Handling and Retries:
Robust Error Handling: Don’t just handle the 400 error. Handle various potential API errors (timeouts, network issues, rate limiting) gracefully. Include retry mechanisms with exponential backoff.
Common Pitfalls & What to Check Next:
Rate Limiting: Monitor your API usage to ensure you aren’t exceeding Notion’s rate limits. Implement delays or throttling if necessary.
Database Schema: Check for any formula properties or dependencies in your database that could cause validation issues due to inconsistent data.
Data Validation: Implement client-side and server-side data validation before sending requests to the Notion API to reduce the chance of invalid data triggering errors.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
Everyone’s right about the page ID issue, but there’s a cleaner way.
I used to waste hours debugging these Notion API calls until I automated the whole thing. The real problem isn’t just your relation format - it’s manually handling all these API calls and data mappings.
I built a system that handles Notion integrations without custom API code. It automatically manages relation lookups, grabs the right page IDs, and formats everything correctly. No more hunting down page IDs or dealing with broken requests.
For your case, you’d set up a simple workflow that takes your task data, finds the matching project automatically, and creates the relation properly. Takes about 10 minutes to configure and kills all the manual API debugging.
Saves me 3-4 hours every week on Notion automations alone. Way better than writing custom scripts for every database operation.
You are encountering an error when attempting to create new database entries in Notion using the API, specifically when dealing with relation fields. Your current request includes the database ID within the relation property, which is incorrect. The Notion API expects the actual page IDs of the related entries, not the database ID itself.
Understanding the “Why” (The Root Cause):
The Notion API’s relation field works by directly linking to specific pages within a database. Providing the database ID only tells the API where the related page might be, but not which page to link to. Think of it like providing a city name instead of a street address – it narrows down the location, but isn’t precise enough to find the correct destination. You need to identify the specific page within the related database that you want to connect to.
Step-by-Step Guide:
Retrieve the Page ID of the Related Project: Before creating your new task entry, you need to obtain the id of the specific project page you want to link to. This requires a separate API call to query the “Project” database. Here’s how you can achieve this:
// Assuming you have your Notion API token and database ID
const notion = require('@notionhq/client')({ auth: 'YOUR_NOTION_API_TOKEN' });
const projectDatabaseId = 'xyz789abc123def456789012345678901'; // Replace with your actual Project database ID
const projectName = 'YourProjectName'; // Replace with the name of your project
async function getProjectId(databaseId,projectName){
try {
const response = await notion.search({
query: projectName,
sort: {
direction: 'ascending',
timestamp: 'last_edited_time'
},
filter: {
property: 'object',
value: 'page'
}
});
const projectPage = response.results.find(result => result.object === 'page' && result.properties.Name && result.properties.Name.title && result.properties.Name.title[0].plain_text === projectName); //Adapt property Name
if (projectPage) {
return projectPage.id;
} else {
console.error(`Project "${projectName}" not found in database ${databaseId}`);
return null;
}
} catch (error) {
console.error('Error fetching project ID:', error);
return null;
}
}
getProjectId(projectDatabaseId, projectName)
.then(projectId => {
if (projectId) {
// Proceed to create the task entry using the projectId
console.log("Project ID:", projectId);
createTask(projectId);
}
});
async function createTask(projectId){
const taskId = await notion.pages.create({
parent: { database_id: 'a1b2c3d4e5f6789012345678901234ab' },
properties: {
Task: {
title: [{ text: { content: 'New Task' } }]
},
Deadline: {
date: { start: '2024-01-15' }
},
Category: {
select: { name: 'Work' }
},
Project: {
relation: [{ id: projectId }]
}
}
});
console.log("Task created with ID:", taskId);
}
Update Your Notion API Request: Once you have the projectId, modify your original JSON request to use it instead of the database ID. Remove the type and synced_property_name fields; they are unnecessary for creating a basic relation. The relation property should simply contain an array of objects, each with an id property referencing a specific page.
{
"parent": { "database_id": "a1b2c3d4e5f6789012345678901234ab" },
"properties": {
"Task": {
"title": [
{
"text": {
"content": "New Task"
}
}
]
},
"Deadline": {
"date": {
"start": "2024-01-15"
}
},
"Category": {
"select": {
"name": "Work"
}
},
"Project": {
"relation": [{ "id": "YOUR_PROJECT_PAGE_ID" }] // Replace YOUR_PROJECT_PAGE_ID with the actual ID obtained in Step 1
}
}
}
Common Pitfalls & What to Check Next:
Incorrect Page ID: Double-check the projectId obtained in Step 1. Even a small typo will cause the relation to fail. Print the projectId to your console to verify it’s correct.
API Rate Limits: If you’re making many requests, you might hit Notion’s API rate limits. Implement error handling and potentially add delays between requests.
Authentication Issues: Ensure your Notion API token is correct and has the necessary permissions. An invalid token will prevent the requests from succeeding.
Database Property Names: Ensure the property name used to search for the Project (projectName in the code example) exactly matches the name of the property in your Notion database. Case sensitivity matters.
Project Existence: Verify that the project you are trying to link to actually exists in the specified database.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
Had this exact problem last month building a project tracker. You’re mixing database IDs with page IDs in your relation field - that’s what’s breaking it. Relations point to pages, not databases. First query the related database to grab the page ID of whatever project you want to link. I just do a separate API call, search by project name, then drop that page ID into the relation field. Way simpler structure than what you’ve got - just the page ID in the relation array.
your relation format’s wrong - you need the actual page id, not the database. use “id”: “page-id-here” instead of database_id. and drop the synced_property_name part, it’s not needed for basic relations.