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.8 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { wafeqAuth } from '../common/auth';
import { wafeqApiCall } from '../common/client';
import { wafeqProps } from '../common/props';

export const reportInvoiceToTaxAuthority = createAction({
  auth: wafeqAuth,
  name: 'report_invoice_to_tax_authority',
  displayName: 'Report Invoice to Tax Authority',
  description:
    'Submit an invoice to the tax authority (ZATCA in Saudi Arabia, FTA in UAE). The invoice must already be finalized in Wafeq before you can report it.',
  audience: 'both',
  aiMetadata: {
    description:
      'Submits an already-finalized Wafeq invoice to the government tax authority (ZATCA in Saudi Arabia, FTA in UAE) for e-invoicing compliance. Choose this after an invoice has been created and moved to Finalized status; it will fail on draft invoices. Requires the invoice ID. Not idempotent — it is a reporting submission against the external authority.',
    idempotent: false,
  },
  props: {
    invoice: wafeqProps.invoiceDropdown({
      description:
        'Pick which invoice to submit. ⚠️ The invoice must be in "Finalized" status first — if you just created it as a Draft, change its status to Finalized in Wafeq before running this action.',
    }),
    idempotency_key: wafeqProps.idempotencyKey,
  },
  async run(context) {
    const { invoice, idempotency_key } = context.propsValue;
    const response = await wafeqApiCall<Record<string, unknown>>({
      apiKey: context.auth.secret_text,
      method: HttpMethod.POST,
      path: `/invoices/${invoice}/tax-authority/report/`,
      idempotencyKey: idempotency_key as string | undefined,
    });
    return {
      invoice_id: invoice,
      status: 'submitted',
      response: response.body,
    };
  },
});