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 { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { createAction, OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
import { trueLayerCommon } from '../../common';

export const createMandate = createAction({
  auth: trueLayerCommon.auth,
  name: 'create-mandate',
  classification: 'WRITE',
  displayName: 'Create Mandate',
  description: 'Create a new mandate. This API must be called using a backend bearer token.',
  audience: 'both',
  aiMetadata: { description: 'Create a new TrueLayer payment mandate (a recurring-payment authorization) using a backend bearer token. Use when setting up variable recurring payments before any individual payment is taken. This writes a new resource each call; supply the optional idempotency key to prevent duplicate mandates on retry.', idempotent: false },
  props: {
    IdempotencyKeyHeader: Property.ShortText({
      displayName: 'Idempotency Key Header',
      description: 'Used to ensure idempotent requests',
      required: false,
    }),
    SignatureHeader: Property.ShortText({
      displayName: 'Signature Header',
      description: 'Used for request signature verification',
      required: false,
    }),
  },
  run: async (ctx) => {
    const response =await  httpClient.sendRequest({
      method: HttpMethod.POST,
      url: `${trueLayerCommon.baseUrl}/v3/mandates`,
      headers: {
        Authorization: `Bearer ${(ctx.auth as OAuth2PropertyValue).access_token}`,
        'Idempotency-Key': ctx.propsValue.IdempotencyKeyHeader,
        'Signature': ctx.propsValue.SignatureHeader,
      },
      body: ctx.propsValue,
    })

    return response.body;
  },
});