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.5 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { paperformAuth } from '../common/auth';
import { paperformCommon } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';
import { PaperformPartialSubmission } from '../common/types';
import { paperformCommonProps } from '../common/props';

export const deletePartialFormSubmission = createAction({
  auth: paperformAuth,
  name: 'deletePartialFormSubmission',
  displayName: 'Delete Partial Form Submission',
  description: 'Deletes a partial/in-progress submission by its ID.',
  audience: 'both',
  aiMetadata: { description: 'Permanently deletes a partial (in-progress, not yet completed) Paperform submission by its ID from the given form. Use to discard an abandoned draft response; this is destructive and not idempotent.', idempotent: false },
  props: {
    formId: paperformCommonProps.formId,
    partialSubmissionId: Property.Dropdown({
      auth: paperformAuth,
      displayName: 'Partial Submission ID',
      required: true,
      refreshers: ['auth', 'formId'],
      options: async ({ auth, formId }) => {
        if (!auth || !formId) {
          return {
            disabled: true,
            placeholder: 'Please select a form first',
            options: [],
          };
        }
        
        try {
          const partialSubmissions = await paperformCommon.getPartialSubmissions({
            formSlugOrId: formId as string,
            auth: auth.secret_text,
            limit: 100,
          });
          
          return {
            disabled: false,
            options: partialSubmissions.results["partial-submissions"].map((partialSubmission: PaperformPartialSubmission) => ({
              label: `${partialSubmission.id}`,
              value: partialSubmission.id,
            })),
          };
        } catch (error) {
          return {
            disabled: true,
            placeholder: 'Error loading partial submissions',
            options: [],
          };
        }
      },
    }),
  },
  async run({ auth, propsValue }) {
    const { partialSubmissionId } = propsValue;
    
    try {
      await paperformCommon.apiCall({
        method: HttpMethod.DELETE,
        url: `/partial-submissions/${partialSubmissionId}`,
        auth: auth.secret_text,
      });
      
      return {
        success: true,
        message: `Partial submission with ID ${partialSubmissionId} has been successfully deleted.`,
      };
    } catch (error: any) {
      throw new Error(`Failed to delete partial submission: ${error.message}`);
    }
  },
});