Skip to content

SOP 003: Create a Database

Fresh Last Updated: January 2025
FieldValue
SOP IDSOP-003
Version1.0
StatusActive
DifficultyIntermediate

Purpose

Create a Notion database programmatically with custom properties (schema), including all common property types.

Prerequisites

  • [ ] Completed authentication setup (SOP 002)
  • [ ] A parent page with integration access
  • [ ] Update content capability enabled

Database Creation Flow

Step-by-Step Instructions

Step 1: Identify Parent Page

Get the page ID where the database will be created:

javascript
// Page ID from URL: https://notion.so/My-Page-abc123...
const parentPageId = 'abc123def456...'; // 32-character ID

Finding the Page ID

  1. Open the page in Notion
  2. Click Share > Copy link
  3. Extract the 32-character ID from the URL

Step 2: Define the Schema

Create the properties object defining your database columns:

javascript
const properties = {
  // Title property (required)
  Name: {
    title: {}
  },

  // Text property
  Description: {
    rich_text: {}
  },

  // Number property
  Priority: {
    number: {
      format: 'number'  // number, number_with_commas, percent, dollar, etc.
    }
  },

  // Select property
  Status: {
    select: {
      options: [
        { name: 'Not Started', color: 'gray' },
        { name: 'In Progress', color: 'blue' },
        { name: 'Done', color: 'green' }
      ]
    }
  },

  // Multi-select property
  Tags: {
    multi_select: {
      options: [
        { name: 'Bug', color: 'red' },
        { name: 'Feature', color: 'purple' },
        { name: 'Documentation', color: 'yellow' }
      ]
    }
  },

  // Date property
  'Due Date': {
    date: {}
  },

  // Checkbox property
  Archived: {
    checkbox: {}
  },

  // URL property
  Link: {
    url: {}
  },

  // Email property
  'Contact Email': {
    email: {}
  },

  // People property
  Assignee: {
    people: {}
  }
};

Step 3: Create the Database

javascript
const { Client } = require('@notionhq/client');
require('dotenv').config();

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

async function createDatabase() {
  const parentPageId = process.env.NOTION_PAGE_ID;

  const response = await notion.databases.create({
    parent: {
      type: 'page_id',
      page_id: parentPageId
    },
    title: [
      {
        type: 'text',
        text: {
          content: 'Project Tasks'
        }
      }
    ],
    properties: {
      // Title (required)
      Name: { title: {} },

      // Status select
      Status: {
        select: {
          options: [
            { name: 'To Do', color: 'gray' },
            { name: 'In Progress', color: 'blue' },
            { name: 'Done', color: 'green' }
          ]
        }
      },

      // Priority number
      Priority: {
        number: { format: 'number' }
      },

      // Due date
      'Due Date': { date: {} },

      // Tags multi-select
      Tags: {
        multi_select: {
          options: [
            { name: 'Urgent', color: 'red' },
            { name: 'Backend', color: 'purple' },
            { name: 'Frontend', color: 'blue' }
          ]
        }
      },

      // Assignee
      Assignee: { people: {} }
    }
  });

  console.log('✅ Database created!');
  console.log('Database ID:', response.id);
  console.log('URL:', response.url);

  return response;
}

createDatabase().catch(console.error);

Step 4: Add Initial Pages

javascript
async function addInitialPages(databaseId) {
  const tasks = [
    {
      Name: 'Set up project structure',
      Status: 'Done',
      Priority: 1,
      Tags: ['Backend']
    },
    {
      Name: 'Implement authentication',
      Status: 'In Progress',
      Priority: 2,
      Tags: ['Backend', 'Urgent']
    },
    {
      Name: 'Design landing page',
      Status: 'To Do',
      Priority: 3,
      Tags: ['Frontend']
    }
  ];

  for (const task of tasks) {
    await notion.pages.create({
      parent: { database_id: databaseId },
      properties: {
        Name: {
          title: [{ text: { content: task.Name } }]
        },
        Status: {
          select: { name: task.Status }
        },
        Priority: {
          number: task.Priority
        },
        Tags: {
          multi_select: task.Tags.map(tag => ({ name: tag }))
        }
      }
    });
    console.log(`Created: ${task.Name}`);
  }
}

Property Types Reference

All Property Type Examples

javascript
// Title (required, one per database)
Name: { title: {} }

// Rich text
Description: { rich_text: {} }
javascript
// Single select
Status: {
  select: {
    options: [
      { name: 'Open', color: 'green' },
      { name: 'Closed', color: 'red' }
    ]
  }
}

// Multi-select
Tags: {
  multi_select: {
    options: [
      { name: 'Bug', color: 'red' },
      { name: 'Feature', color: 'blue' }
    ]
  }
}
javascript
// Number with format
Price: {
  number: { format: 'dollar' }
}

// Date
'Due Date': { date: {} }
javascript
// Relation to another database
'Related Tasks': {
  relation: {
    database_id: 'other-database-id',
    single_property: {}
  }
}

// Rollup
'Total Hours': {
  rollup: {
    relation_property_name: 'Tasks',
    rollup_property_name: 'Hours',
    function: 'sum'
  }
}

Verification Checklist

  • [ ] Database appears in parent page
  • [ ] All properties visible in Notion UI
  • [ ] Select options show correct colors
  • [ ] Initial pages created successfully
  • [ ] Database ID stored for future use

Troubleshooting

ErrorCauseSolution
404 Parent not foundPage doesn't exist or no accessShare page with integration
400 Invalid propertySchema syntax errorCheck property format
403 ForbiddenMissing capabilitiesEnable "Insert content"
Duplicate titleTitle property already existsOnly one title allowed

Common Mistakes

  1. Multiple title properties - Only one title property per database
  2. Invalid color names - Use only supported colors: default, gray, brown, orange, yellow, green, blue, purple, pink, red
  3. Missing required title - Every database needs exactly one title property

See Also

Built with VitePress | Powered by Claude AI