Getting 400 error when adding pages to Notion database via API

I’m trying to add new pages to my Notion database using the API but keep running into issues. The main problem happens when I try to set properties that aren’t simple text fields.

const { Client } = require('@notionhq/client');

const client = new Client({
  auth: process.env.NOTION_API_KEY,
});

async function addPage() {
  try {
    const response = await client.pages.create({
      parent: {
        type: 'database_id',
        database_id: process.env.DATABASE_ID,
      },
      properties: {
        Title: [
          {
            text: {
              content: 'Sample Title',
            },
          },
        ],
        Website: {
          url: 'https://example.com',
        },
        Description: [
          {
            text: {
              content: 'test description',
            },
          },
        ],
        Date: [
          {
            text: {
              content: '2023',
            },
          },
        ],
      },
    });
  } catch (err) {
    console.log(err);
  }
}

addPage();

Text fields work fine but I get errors like this for URL fields:

body.properties.Website.id should be defined, instead was `undefined`.
body.properties.Website.name should be defined, instead was `undefined`.
body.properties.Website.start should be defined, instead was `undefined`.

This same issue happens with other property types like checkboxes and relations too. My API token and database permissions are set up correctly. What am I missing in the property structure?

Had this exact problem last month migrating data to Notion. Those error messages mean you’re not matching the property structure right. Your Website property looks fine - that’s the correct format for URL fields. The real issue is your other properties. Title fields need { title: [{ text: { content: 'Sample Title' } }] } and Description should be { rich_text: [{ text: { content: 'test description' } }] } if it’s rich text. Dates need { date: { start: '2023-01-01' } } with proper ISO format. Each property type has different formatting requirements, which is the tricky part. I’d check Notion’s API explorer or your database schema first to see exactly what property types you’re dealing with, then match the structure.

Your structure’s wrong for most property types. Each one has different format requirements. Title and Description need to be wrapped in rich_text objects, not plain arrays. Your Date field should use the date type with proper ISO formatting - don’t put it in as text. I hit the same issues when I started with Notion’s API. Their docs are confusing because they mix response and request formats. Check the specific property examples in their API reference. Also double-check your database schema matches exactly what you’re inserting - property names are case-sensitive.

Those error messages mean Notion wants metadata fields you didn’t include. Usually happens when your property structure doesn’t match what the database expects. I hit this same issue last month with a client’s integration. The problem’s usually how you define the parent database or property names that don’t match up. Double-check your DATABASE_ID is right and that property names in your code match exactly what’s in your Notion database - they’re case-sensitive. Also make sure you’re using an integration token with write permissions for that database. Sometimes it’s not the property structure at all, just authentication scope.

Been working with Notion’s API for a while - this error usually means you’re sending properties in the wrong format. Notion’s error messages are terrible at showing the real issue.

Your URL syntax looks right, so the problem’s probably somewhere else. First thing: log your database schema using the retrieve database endpoint. Check what property types you’re actually dealing with. Sometimes what looks like a URL field in the UI is configured as something totally different.

Also watch out for extra properties that don’t exist in your database - Notion throws 400 errors for those too. Property names have to match exactly, including spaces and special characters.

u might be mixing up rich text with simple types. for title and desc., try using rich_text not plain text. the date prop needs to be date type with the right format - not just text. check the Notion API docs for the specifics on property types.

Those error messages are confusing, but it’s usually because the property types don’t match what’s in your database. Try using client.databases.retrieve() first to check the actual property schema - sometimes what looks like a URL field is actually set up as rich text or something else in Notion.

Your code’s property structure is messed up. For title properties, you can’t pass the array directly - wrap it in a ‘title’ key instead. So your Title should be Title: { title: [{ text: { content: 'Sample Title' } }] }. The URL property looks fine though. For Description, if it’s rich text, use Description: { rich_text: [{ text: { content: 'test description' } }] }. Date properties are different - use Date: { date: { start: '2023-01-01' } } with proper ISO format, not text content. Each property type needs its own wrapper object that matches your database column type. Check your database schema to make sure you’re using the right property types.

you’re mixing up property formats. for URL fields, wrap it in an object like Website: { url: 'https://example.com' } - no array brackets needed. same issue’s probably hittin ur other field types too. check the notion API docs for each property type’s structure.

Your URL field structure looks fine. The real issue is probably property name mismatches between your code and database schema. I’ve hit similar 400 errors before - they’re usually from tiny differences in property names or types. First, log your database properties with client.databases.retrieve() to see exactly what property names and types Notion wants. Your Title property needs rich_text format, not that array structure you’ve got. For the Date field, if it’s actually a date property in your database, use { date: { start: '2023-01-01' } } instead of text content. Those error messages about missing id, name, and start fields mean Notion’s expecting different property metadata than what you’re sending.