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 } from '@activepieces/pieces-framework';
import { ApitemplateAuth } from '../common/auth';
import { ApitemplateRegion, makeRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';
import { getAccountInformationOutputSchema } from '../output-schemas';

export const getAccountInformation = createAction({
  auth: ApitemplateAuth,
  name: 'getAccountInformation',
  outputSchema: getAccountInformationOutputSchema,
  classification: 'READ',
  displayName: 'Get Account Information',
  description: 'Retrieves account information including usage statistics and account details.',
  audience: 'both',
  aiMetadata: { description: 'Fetches the APITemplate.io account profile, including plan and generation usage/quota stats. Use to check remaining quota or account status before generating documents. Read-only and idempotent; takes no input.', idempotent: true },
  props: {},
  async run({ auth }) {
    const authConfig = auth.props;

    const endpoint = '/account-information';

    try {
      const response = await makeRequest(
        authConfig.apiKey,
        HttpMethod.GET,
        endpoint,
        undefined,
        undefined,
        authConfig.region as ApitemplateRegion
      );

      return response;
    } catch (error: any) {
     
      if (error.message.includes('502') && authConfig.region !== 'default') {
        throw new Error(
          `${error.message}\n\nThe ${authConfig.region} region appears to be experiencing issues. ` +
          `Consider switching to the 'default' region in your authentication settings or try again later.`
        );
      }
      throw error;
    }
  },
});