// Define the Notion resource type as required for the function
type Notion = {
token: string
}
export async function main(notion: Notion, pageId: string, propertyUpdates: any): Promise<any> {
// URL to update a specific page
const pageUrl = `https://api.notion.com/v1/pages/${pageId}`;
// Set up the request headers
const headers = {
'Authorization': `Bearer ${notion.token}`,
'Notion-Version': '2022-06-28', // Use the latest version supported by your integration
'Content-Type': 'application/json'
};
// Set up the body with property updates
const body = {
properties: propertyUpdates
};
// Perform the fetch request to update the Notion page
try {
const response = await fetch(pageUrl, {
method: 'PATCH', // The Notion API requires a PATCH request to update a page
headers: headers,
body: JSON.stringify(body)
});
// Check if the request was successful
if (!response.ok) {
throw new Error(`Failed to update Notion page: ${response.status} ${response.statusText}`);
}
// Parse the JSON response
const data = await response.json();
// Return the updated data
return data;
} catch (error) {
console.error('Error updating Notion page:', error);
throw error; // Rethrow the error to be handled by the caller
}
}
Submitted by henri186 250 days ago