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

export const downloadStandardPDF = createAction({
  auth: kizeoFormsAuth,
  name: 'download_standard_pdf', // Must be a unique across the piece, this shouldn't be changed.
  classification: 'READ',
  displayName: 'Download Standard PDF',
  description: 'Get PDF data of a form',
  audience: 'both',
  aiMetadata: { description: 'Download the standard PDF rendering of one submitted Kizeo Forms data record, identified by form ID and data ID, returned as a base64 data URI. Use when you need the generated PDF document for a specific submission. Read-only and idempotent.', idempotent: true },
  props: {
    formId: kizeoFormsCommon.formId,
    dataId: Property.Number({
      displayName: 'Data Id',
      description: undefined,
      required: true,
    }),
  },
  async run(context) {
    const { formId, dataId } = context.propsValue;
    const response = await httpClient.sendRequest<Buffer>({
      method: HttpMethod.GET,
      url:
        endpoint +
        `v3/forms/${formId}/data/${dataId}/pdf?used-with-actives-pieces=`,
      headers: {
        'Content-Type': 'application/pdf',
        Authorization: context.auth.secret_text,
      },
      responseType: 'arraybuffer',
    });

    if (response.status === 200) {
      return (
        'data:application/pdf;base64,' +
        Buffer.from(response.body).toString('base64')
      );
    }

    return [];
  },
});