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

888 B
Raw Blame
import { PieceAuth } from '@activepieces/pieces-framework';
import { tryCatch } from '@activepieces/pieces-framework';
import { kustomerClient } from './client';

export const kustomerAuth = PieceAuth.SecretText({
  displayName: 'API Token',
  description: `Authenticate using a Kustomer API token.

Paste a private Kustomer API token with access to customers, conversations, and KObjects.`,
  required: true,
  validate: async ({ auth }) => {
    const apiKey = auth as string;

    if (!apiKey) {
      return {
        valid: false,
        error: 'Invalid API token.',
      };
    }

    const { error } = await tryCatch(() =>
      kustomerClient.validateAuth({
        apiKey,
      })
    );

    if (error) {
      return {
        valid: false,
        error: 'Invalid API token or missing Kustomer permissions.',
      };
    }

    return {
      valid: true,
    };
  },
});