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 { airtableAuth } from '../auth';
import { airtableCommon } from '../common';
import { AirtableFieldConfig } from '../common/models';
import { createTableActionOutputSchema } from '../output-schemas';

export const airtableCreateTableAction = createAction({
  auth: airtableAuth,
  name: 'airtable_create_table',
  classification: 'WRITE',
  displayName: 'Create Table',
  description: 'Create a new table in an existing base.',
  audience: 'human',
  outputSchema: createTableActionOutputSchema,
  aiMetadata: {
    description:
      'Creates a new table in an existing base from a JSON array of field definitions (the first field becomes the primary field), with an optional table description. Use to add a table to a base you already have. Not idempotent — each call creates a new table.',
    idempotent: false,
  },
  props: {
    base: airtableCommon.base,
    name: Property.ShortText({
      displayName: 'Table Name',
      required: true,
    }),
    description: Property.LongText({
      displayName: 'Description',
      description: 'Shown under the table name in Airtable.',
      required: false,
      advanced: true,
    }),
    fields: Property.Json({
      displayName: 'Fields',
      description:
        'Fields for the table. The first one becomes the primary field.',
      required: true,
      defaultValue: [
        {
          name: 'Name',
          type: 'singleLineText',
          description: 'This will be the primary field',
        },
        {
          name: 'Notes',
          type: 'multilineText',
        },
      ],
    }),
  },
  async run(context) {
    const { auth: personalToken, propsValue } = context;
    const { base: baseId, name, description, fields } = propsValue;

    return await airtableCommon.createTable({
      personalToken: personalToken.secret_text,
      baseId: baseId as string,
      name: name as string,
      description: description as string | undefined,
      fields: fields as unknown as AirtableFieldConfig[],
    });
  },
});