Skip to content

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

2.4 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { attioAuth } from '../auth';
import { attioApiCall } from '../common/client';
import { objectTypeIdDropdown } from '../common/props';
import { attioCreateNoteOutputSchema } from '../output-schemas';

export const createNoteAction = createAction({
	name: 'create_note',
	outputSchema: attioCreateNoteOutputSchema,
	classification: 'WRITE',
	displayName: 'Create Note',
	description: 'Creates a new note on a record.',
	audience: 'human',
	aiMetadata: { description: 'Creates a note attached to a specific record, with a title and body content interpreted as either plaintext or markdown. Requires the parent object type, the parent record ID, and the note text. Not idempotent — each call appends another note to the record.', idempotent: false },
	auth: attioAuth,
	props: {
		parentObject: objectTypeIdDropdown({
			displayName: 'Parent Object',
			description: 'The object type the record belongs to (e.g. person, company).',
			required: true,
		}),
		parentRecordId: Property.ShortText({
			displayName: 'Parent Record ID',
			description: 'The ID of the record to attach this note to.',
			required: true,
		}),
		title: Property.ShortText({
			displayName: 'Title',
			description: 'The plaintext title of the note.',
			required: true,
		}),
		format: Property.StaticDropdown({
			displayName: 'Format',
			description: 'How the note content should be interpreted.',
			required: true,
			defaultValue:'plaintext',
			options: {
				disabled: false,
				options: [
					{ label: 'Plaintext', value: 'plaintext' },
					{ label: 'Markdown', value: 'markdown' },
				],
			},
		}),
		content: Property.LongText({
			displayName: 'Content',
			description: 'The body of the note.',
			required: true,
		}),
	},
	async run(context) {
		const accessToken = context.auth.secret_text;
		const { parentObject, parentRecordId, title, format, content } = context.propsValue;

		const body: Record<string, unknown> = {
			parent_object: parentObject,
			parent_record_id: parentRecordId,
			title,
			format,
			content,
		};

		// https://docs.attio.com/rest-api/endpoint-reference/notes/create-a-note
		const response = await attioApiCall<{ data: Record<string, unknown> }>({
			method: HttpMethod.POST,
			accessToken,
			resourceUri: '/notes',
			body: { data: body },
		});

		return response.data;
	},
});