AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createAction } from '@activepieces/pieces-framework';
import { Client } from '@notionhq/client';
import { notionAuth } from '../auth';
import { getNotionToken, notionCommon } from '../common';
import { restoreDatabaseItemActionOutputSchema } from '../output-schemas';
export const restoreDatabaseItem = createAction({
auth: notionAuth,
name: 'restore_database_item',
classification: 'WRITE',
displayName: 'Restore Database Item',
description: 'Restore an archived database item.',
audience: 'human',
aiMetadata: {
description:
'Un-archives a previously archived Notion database item, returning it to active status. Use when an agent must recover a record that was archived; requires the database_id and the archived item id. Idempotent: restoring an already-active item leaves it active.',
idempotent: true,
},
propertyGroups: [
{
key: 'item',
display: 'section',
label: 'Database item',
icon: 'inbox',
props: ['database_id', 'archived_item_id'],
},
],
props: {
database_id: notionCommon.database_id,
archived_item_id: notionCommon.archived_database_item_id,
},
outputSchema: restoreDatabaseItemActionOutputSchema,
async run(context) {
const { database_id, archived_item_id } = context.propsValue;
if (!database_id) {
throw new Error('Database selection is required');
}
if (!archived_item_id) {
throw new Error('Please select an archived item to restore');
}
const notion = new Client({
auth: getNotionToken(context.auth),
notionVersion: '2022-02-22',
});
try {
const response = await notion.pages.update({
page_id: archived_item_id,
archived: false,
});
let itemTitle = 'Database item';
let itemUrl = undefined;
if ('properties' in response && response.properties) {
const firstProperty = Object.values(response.properties)[0];
if (
firstProperty &&
typeof firstProperty === 'object' &&
'title' in firstProperty &&
firstProperty.title
) {
itemTitle =
(firstProperty.title as any)[0]?.plain_text || 'Untitled item';
}
}
if ('url' in response) {
itemUrl = response.url;
}
return {
success: true,
message: `"${itemTitle}" has been successfully restored and is now active`,
restoredItem: {
id: response.id,
title: itemTitle,
url: itemUrl,
restored_at: new Date().toISOString(),
},
fullResponse: response,
};
} catch (error: any) {
if (
error.message?.includes('permissions') ||
error.message?.includes('unauthorized')
) {
throw new Error(
'Unable to restore item: Your Notion integration may lack edit permissions for this database. Please check your integration permissions in Notion.'
);
}
if (error.message?.includes('not_found')) {
throw new Error(
'The selected item could not be found. It may have been permanently deleted or moved to a different database.'
);
}
throw new Error(`Failed to restore database item: ${error.message}`);
}
},
});