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

2.3 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { xeroAuth } from '../..';
import { props } from '../common/props';
import { xeroInput } from '../common/client';
import { xeroReports } from '../common/reports';
import { xeroOutputSchemas } from '../output-schemas';

export const xeroGetBalanceSheet = createAction({
  auth: xeroAuth,
  name: 'xero_get_balance_sheet',
  classification: 'READ',
  displayName: 'Get Balance Sheet',
  description: 'Runs the Balance Sheet report as at a date, with optional comparison periods.',
  audience: 'both',
  aiMetadata: {
    description:
      'Runs the Balance Sheet report as at a date (defaults to the end of the current month) and returns flat rows with a section, a label and one value per column, optionally compared with earlier periods. Read-only and idempotent.',
    idempotent: true,
  },
  outputSchema: xeroOutputSchemas.report,
  props: {
    tenant_id: props.tenant_id,
    date: Property.ShortText({ displayName: 'As At Date (YYYY-MM-DD)', required: false }),
    timeframe: Property.StaticDropdown({
      displayName: 'Period Length',
      description: 'Length of each comparison period.',
      required: false,
      options: { options: [{ label: 'Month', value: 'MONTH' }, { label: 'Quarter', value: 'QUARTER' }, { label: 'Year', value: 'YEAR' }] },
    }),
    periods: Property.Number({ displayName: 'Comparison Periods', description: 'Number of earlier periods to compare with, 1 to 11.', required: false }),
    standard_layout: Property.Checkbox({ displayName: 'Standard Layout', description: 'Ignore custom report layouts.', required: false }),
    payments_only: Property.Checkbox({ displayName: 'Cash Basis (Payments Only)', required: false }),
  },
  async run(context) {
    const values = context.propsValue;
    const params = {
      date: xeroInput.parseDateInput({ value: values.date, field: 'As At Date' }),
      periods: xeroReports.periodsParam({ value: values.periods }),
      timeframe: values.timeframe,
      standardLayout: values.standard_layout,
      paymentsOnly: values.payments_only,
    };
    return xeroReports.fetchReport({
      accessToken: context.auth.access_token,
      tenantId: values.tenant_id,
      report: 'BalanceSheet',
      queryParams: xeroReports.definedParams({ params }),
    });
  },
});