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

1.9 KB
Raw Blame
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import FormData from 'form-data';
import { airparserAuth } from '../auth';
import { BASE_URL } from '../common';
import { inboxIdDropdown } from '../common/props';

export const uploadDocumentAction = createAction({
	auth: airparserAuth,
	name: 'upload_document',
	classification: 'WRITE',
	displayName: 'Upload Document',
	description: 'Upload a document to an Airparser inbox for parsing.',
	audience: 'both',
	aiMetadata: { description: 'Uploads a file to a specified Airparser inbox so it can be parsed into structured data; requires the inbox ID and the file. Use to submit a new document (PDF, email, image, etc.) for extraction. Not idempotent: each call creates a new document, and parsing completes asynchronously, so retrieve the results separately once parsing finishes.', idempotent: false },
	props: {
		inboxId: inboxIdDropdown,
		file: Property.File({
			displayName: 'File',
			description: 'The document file to upload for parsing.',
			required: true,
		}),
		fileName: Property.ShortText({
			displayName: 'File Name',
			required: false,
		}),
		meta: Property.Object({
			displayName: 'Metadata',
			description: 'Optional metadata to associate with the document.',
			required: false,
		}),
	},
	async run(context) {
		const { inboxId, file, meta, fileName } = context.propsValue;

		const formData = new FormData();
		formData.append('file', Buffer.from(file.base64, 'base64'), fileName || file.filename);

		if (meta) {
			formData.append('meta', JSON.stringify(meta));
		}

		const response = await httpClient.sendRequest({
			method: HttpMethod.POST,
			url: BASE_URL + `/inboxes/${inboxId}/upload`,
			headers: {
				...formData.getHeaders(),
				'X-API-Key': context.auth.secret_text,
			},
			body: formData,
		});

		return { docId: response.body };
	},
});