Welcome! Share code as fast as possible.

// FUNCTION FOR MOVING NOTION DATABASE PAGE TEXT PROPERTY INTO THE PAGE BODY

// ENSURE YOU HAVE A TEXT PROPERTY CALLED "carddescription" OR EDIT THE SCRIPT BELOW
// ENSURE YOU HAVE A CHECKBOX PROPERTY CALLED "hitbyscript" OR EDIT THE SCRIPT BELOW.
// AFTER THE SCRIPT IS DONE YOU CAN REMOVE THE PROPERTIES

function aiFunction2 () {
  const token = "YOUR NOTION INTEGRATION TOKEN";
  const databaseIdWR = "YOUR NOTION DATABASE ID";

  const pageIds = []; // Initialize the array to store page IDs
  
  let url = "https://api.notion.com/v1/databases/" + databaseIdWR + "/query";

  var data = { 
    "filter": {
        "and": [
            { "property": "carddescription", "text": { "is_not_empty": true } }, // Existing filter
            { "property": "hitbyscript", "checkbox": { "equals": false } }       // Additional filter
        ]
    } 
  };

  var options = {
    method: 'post',
    headers : {"Authorization": "Bearer " + token, "Content-Type": "application/json", "Notion-Version": "2021-05-13"},
    payload: JSON.stringify(data),
    muteHttpExceptions: false // For better error visibility
  };

  const responseWR = UrlFetchApp.fetch(url, options);
  const dataoutput = JSON.parse(responseWR.getContentText());

  // Process each item with a carddescription
  dataoutput.results.forEach(result => {
    const pageIdWR = result.id;
    pageIds.push(pageIdWR);
    const cardDescription = result.properties.carddescription.rich_text[0].plain_text;

    // Update page content using append block children endpoint
    const updateUrl = `https://api.notion.com/v1/blocks/${pageIdWR}/children`;
    const updateData = {
      "children": [
        {
          "object": "block",
          "type": "paragraph",
          "paragraph": {
            "rich_text": [{ "type": "text", "text": { "content": cardDescription } }]
          }
        }
      ]
    };

    const updateOptions = {
      method: 'patch', // Method for appending content
      headers : {
        "Authorization": "Bearer " + token, 
        "Content-Type": "application/json", 
        "Notion-Version": "2022-06-28" 
      },
      payload: JSON.stringify(updateData),
      muteHttpExceptions: false
    };

    try {
      const response = UrlFetchApp.fetch(updateUrl, updateOptions); 
      const checkUrl = `https://api.notion.com/v1/pages/${pageIdWR}`;
      console.log(`Page ${pageIdWR} updated successfully`);
      const checkData = {
        "properties": {
            "hitbyscript": { "checkbox": true }
        }
      };

      const checkOptions = {
        method: 'patch', // Method for appending content
        headers : {
          "Authorization": "Bearer " + token, 
          "Content-Type": "application/json", 
          "Notion-Version": "2022-06-28" 
        },
        payload: JSON.stringify(checkData),
        muteHttpExceptions: false
      };
      
      UrlFetchApp.fetch(checkUrl, checkOptions);
      console.log(`Page ${pageIdWR} checked successfully`);
    } catch (error) {
      console.error(`Error updating page ${pageIdWR}: `, error); 
    } 
  });
  console.log("Page IDs:", pageIds); 
}