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.8 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import {
  HttpMethod,
  HttpRequest,
  httpClient,
} from '@activepieces/pieces-common';
import { CARBONE_API_URL, CARBONE_VERSION } from '../common/constants';
import { carboneAuth } from '../auth';
import { carboneProps } from '../common/props';

export const deleteTemplateAction = createAction({
  auth: carboneAuth,
  name: 'carbone_delete_template',
  classification: 'DESTRUCTIVE',
  displayName: 'Delete Template',
  description: 'Delete a Carbone template by its ID.',
  audience: 'both',
  aiMetadata: {
    description: 'Permanently deletes a stored Carbone template (or specific version) identified by its template/version ID. Use to remove a template that is no longer needed. Not idempotent: the first call removes the template and a repeat call on the same ID fails because it no longer exists.',
    idempotent: false,
  },
  props: {
    templateId: carboneProps.templateDropdown({
      displayName: 'Template ID or Version ID',
      description: 'Select a template to delete.',
    }),
  },
  async run(context) {
    const { templateId } = context.propsValue;

    const request: HttpRequest = {
      method: HttpMethod.DELETE,
      url: `${CARBONE_API_URL}/template/${templateId}`,
      headers: {
        Authorization: `Bearer ${context.auth.secret_text}`,
        'carbone-version': CARBONE_VERSION,
      },
    };

    const response = await httpClient.sendRequest<{
      success: boolean;
      error?: string;
    }>(request);

    if (!response.body.success) {
      throw new Error(
        `Failed to delete template: ${response.body.error ?? 'Unknown error'}`
      );
    }

    return {
      success: true,
      templateId,
      message: `Template ${templateId} deleted successfully.`,
    };
  },
});