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.6 KB
Raw Blame
import MailerLite from '@mailerlite/mailerlite-nodejs';
import { MarkdownVariant, Property, createAction } from '@activepieces/pieces-framework';
import { mailerLiteAuth } from '../auth';
import { unsubscribeSubscriberOutputSchema } from '../output-schemas';

export const unsubscribeSubscriberAction = createAction({
	auth: mailerLiteAuth,
	name: 'unsubscribe_subscriber',
	classification: 'DESTRUCTIVE',
	displayName: 'Unsubscribe Subscriber',
	description: 'Set a subscriber status to unsubscribed.',
	audience: 'both',
	aiMetadata: {
		description:
			'Mark a MailerLite subscriber as unsubscribed by email address, so they stop receiving campaigns while their record and history are retained. Use this for opt-out handling; use Delete Subscriber only when the record itself must go. Idempotent: unsubscribing an already-unsubscribed contact leaves them unchanged.',
		idempotent: true,
	},
	outputSchema: unsubscribeSubscriberOutputSchema,
	propertyGroups: [
		{
			key: 'subscriber',
			display: 'section',
			label: 'Subscriber',
			icon: 'user',
			props: ['email', 'unknown_info'],
		},
	],
	props: {
		email: Property.ShortText({
			displayName: 'Email',
			placeholder: '[email protected]',
			required: true,
		}),
		unknown_info: Property.MarkDown({
			value: 'An email that is not on your list yet is added as unsubscribed.',
			variant: MarkdownVariant.INFO,
		}),
	},
	async run(context) {
		const client = new MailerLite({ api_key: context.auth.secret_text });
		const response = await client.subscribers.createOrUpdate({
			email: context.propsValue.email,
			status: 'unsubscribed',
		});
		return response.data;
	},
});