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.0 KB
Raw Blame
import { HttpMethod, httpClient } from '@activepieces/pieces-common';

export const chargekeepCommon = {
  subscribeWebhook: async (
    eventName: string,
    baseUrl: string,
    apiKey: string,
    webhookUrl: string
  ) => {
    const request = {
      method: HttpMethod.POST,
      url: `${baseUrl}/api/services/Platform/Event/Subscribe`,
      headers: {
        'api-key': apiKey,
        'Content-Type': 'application/json',
      },
      body: {
        eventName: eventName,
        targetUrl: webhookUrl,
      },
    };

    const res = await httpClient.sendRequest(request);

    const { id: webhookId } = res.body.result;

    return webhookId;
  },

  unsubscribeWebhook: async (
    baseUrl: string,
    apiKey: string,
    webhookId: number
  ) => {
    const request = {
      method: HttpMethod.POST,
      url: `${baseUrl}/api/services/Platform/Event/Unsubscribe?id=${webhookId}`,
      headers: {
        'api-key': apiKey,
        'Content-Type': 'application/json',
      },
    };

    return await httpClient.sendRequest(request);
  },
};