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.0 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod, httpClient } from '@activepieces/pieces-common';

import { ghostAuth } from '../auth';
import { common } from '../common';
import { ghostOriginalMembersOutputSchema } from '../output-schemas';

export const createMember = createAction({
  name: 'create_member',
  outputSchema: ghostOriginalMembersOutputSchema,
  classification: 'WRITE',
  displayName: 'Create Member',
  description: 'Create a new member',
  audience: 'human',
  aiMetadata: { description: 'Creates a new member in a Ghost publication from an email (required), with optional name, internal note, and newsletter subscriptions. Use to add a subscriber/member to the audience. Not idempotent: each call creates a member and re-running with the same email may produce a duplicate or error.', idempotent: false },
  auth: ghostAuth,
  props: {
    email: Property.ShortText({
      displayName: 'Email',
      required: true,
    }),
    name: Property.ShortText({
      displayName: 'Full Name',
      required: false,
    }),
    note: Property.ShortText({
      displayName: 'Note',
      required: false,
    }),
    newsletters: common.properties.newsletters(false),
  },

  async run(context) {
    const newsletters: any[] = [];
    if (context.propsValue.newsletters) {
      context.propsValue.newsletters.forEach((newsletter: any) => {
        newsletters.push({
          id: newsletter,
        });
      });
    }

    const response = await httpClient.sendRequest({
      url: `${context.auth.props.baseUrl}/ghost/api/admin/members`,
      method: HttpMethod.POST,
      headers: {
        Authorization: `Ghost ${common.jwtFromApiKey(context.auth.props.apiKey)}`,
      },
      body: {
        members: [
          {
            email: context.propsValue.email,
            name: context.propsValue.name,
            note: context.propsValue.note,
            newsletters: newsletters,
          },
        ],
      },
    });

    return response.body;
  },
});