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

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

export const createPost = createAction({
  name: 'create_post',
  outputSchema: ghostOriginalCreatePostOutputSchema,
  classification: 'WRITE',
  displayName: 'Create Post',
  description: 'Create a new post',
  audience: 'human',
  aiMetadata: { description: 'Creates a new post in a Ghost publication from a title and HTML content, with the status controlling whether it is saved as a draft, published immediately, or scheduled (scheduled requires a future Published At). Supports optional slug, excerpt, author, tags, and a featured flag. Not idempotent: each call creates a separate post.', idempotent: false },
  auth: ghostAuth,
  props: {
    title: Property.ShortText({
      displayName: 'Title',
      required: true,
    }),
    slug: Property.ShortText({
      displayName: 'Slug',
      required: false,
    }),
    status: Property.StaticDropdown({
      displayName: 'Status',
      required: true,
      options: {
        options: [
          { label: 'Draft', value: 'draft' },
          { label: 'Published', value: 'published' },
          { label: 'Scheduled', value: 'scheduled' },
        ],
      },
    }),
    publishedAt: Property.DateTime({
      displayName: 'Published At',
      required: false,
    }),
    html: Property.LongText({
      displayName: 'Content (HTML)',
      required: true,
    }),
    customExcerpt: Property.ShortText({
      displayName: 'Custom Excerpt',
      required: false,
    }),
    author: common.properties.author,
    featured: Property.Checkbox({
      displayName: 'Featured',
      required: false,
    }),
    tags: common.properties.tags,
  },

  async run(context) {
    const response = await httpClient.sendRequest({
      url: `${context.auth.props.baseUrl}/ghost/api/admin/posts`,
      method: HttpMethod.POST,
      headers: {
        Authorization: `Ghost ${common.jwtFromApiKey(context.auth.props.apiKey)}`,
      },
      body: {
        posts: [
          {
            title: context.propsValue.title,
            slug: context.propsValue.slug,
            status: context.propsValue.status,
            html: context.propsValue.html,
            published_at: context.propsValue.publishedAt,
            authors: [context.propsValue.author],
            featured: context.propsValue.featured,
            custom_excerpt: context.propsValue.customExcerpt,
            tags: context.propsValue.tags,
          },
        ],
      },
      queryParams: {
        source: 'html',
      },
    });

    return response.body;
  },
});