How to insert records into Notion database using Google Apps Script

I’m working on connecting to the Notion API through Google Apps Script to add new entries to my database. My current setup throws a validation error about the parent property being undefined. I think there might be an issue with how I’m structuring the request payload but I can’t pinpoint the exact problem.

function addNotionRecord() {
  const apiUrl = "https://api.notion.com/v1/pages";
  
  var requestConfig = {
    'muteHttpExceptions': true,
    "method": "POST",
    "headers": {
      Authorization: `Bearer secret_*****`,
      "Content-Type": "application/json",
      "Notion-Version": "2021-05-13",
    },
    "payload": JSON.stringify({
      "parent": {
        "database_id": "*****"
      },
      "properties": {
        "Title": {
          "title": [{
            "text": {
              "content": "NEW RECORD VIA API"
            }
          }]
        }
      }
    })
  };
  
  const result = UrlFetchApp.fetch(apiUrl, requestConfig);
  console.log(result.getContentText());
}

The error I’m getting says the parent property is undefined. Has anyone successfully integrated Notion API with Apps Script before?

had this exact issue last month. check if your integration token has write access - go to notion settings > connections and verify your integration is added to that specific database. also log result.getResponseCode() to see if ur getting a 401 or 400 error, that’ll help narrow it down.

I’ve encountered a similar issue when working with Notion’s API through Google Apps Script. The problem might stem from the format of the database_id or the setup of your properties. Ensure the database_id is a 32-character UUID without dashes, retrieved from your database URL (the string after the last slash). Additionally, check that the “Title” property exactly matches what exists in your Notion database, as property names are case-sensitive. Implement logging for the response status code and full error message to pinpoint the failure. Also, verify that your integration has the necessary write permissions for the database, as this is a common oversight. The structure of your parent property appears correct.

Check your database_id format - needs to be exactly 32 characters, no hyphens. When you copy the database URL from Notion, grab everything after the last slash but before any query parameters. Your payload looks right, but I’d add some debugging to see what’s actually being sent. Log the stringified payload before making the request to make sure it’s formatted properly. The bearer token tripped me up too - you need the internal integration token, not a user token. Also make sure your integration has access to the specific database through the database settings. That parent property undefined error usually means either your database_id is malformed or there’s a permission issue, not a problem with your request structure.