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 { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { webflowAuth } from '../../../auth';
import { webflowAiProps } from '../../../common/ai-props';
import { webflowClient } from '../../../common/client';
import { webflowGetPageCustomCodeOutputSchema } from '../../../output-schemas';

export const upsertPageCustomCodeAction = createAction({
	auth: webflowAuth,
	name: 'webflow_upsert_page_custom_code',
	outputSchema: webflowGetPageCustomCodeOutputSchema,
	displayName: 'Upsert Page Custom Code',
	description: 'Applies registered scripts to a page, replacing the scripts applied before.',
	audience: 'ai',
	classification: 'WRITE',
	aiMetadata: {
		description:
			'Sets the registered scripts applied to a page. The PUT replaces the whole list, so include every script that should stay applied (read them first with Get Page Custom Code); a script left out is removed. Register a script first with Register Hosted Script or Register Inline Script. Get the page id from List Pages.',
		idempotent: true,
	},
	props: {
		pageId: webflowAiProps.pageId({ required: true }),
		scripts: Property.Json({
			displayName: 'Scripts',
			description:
				'The full list of scripts to apply, as a JSON array of {"id", "version", "location": "header" | "footer", "attributes"?: {}}. id and version come from Register Hosted Script, Register Inline Script or List Registered Scripts. Send [] to remove all.',
			required: true,
		}),
	},
	async run(context) {
		const { pageId, scripts } = context.propsValue;
		if (!Array.isArray(scripts)) {
			throw new Error('scripts must be a JSON array of {"id", "version", "location"} objects.');
		}
		return await webflowClient.request<unknown>({
			auth: context.auth,
			method: HttpMethod.PUT,
			path: `/v2/pages/${encodeURIComponent(pageId)}/custom_code`,
			body: { scripts },
		});
	},
});