# Integrations

Read, query, and execute actions on native integrations (Xero, MYOB, etc.). Connecting and disconnecting integrations is done via the platform UI (OAuth browser flows).

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### GET /integrations

List all integrations.

**Scopes:** `integrations:read` — [full detail](./integrations/get-integrations.md)

### GET /integrations/:id

Retrieve an integration.

**Scopes:** `integrations:read` — [full detail](./integrations/get-integrations-id.md)

### POST /integrations/:id/query

Query data from an integration (read-only). Supported Xero query_types: xero_contacts (params: page?, search?), xero_contact_detail (params: contact_id), xero_accounts (params: type?), xero_tax_rates (params: status?), xero_invoices (params: page?, statuses?, date_from?, date_to?), xero_invoices_by_contact (params: contact_id, statuses?), xero_profit_and_loss (params: from_date?, to_date?, periods?, timeframe?, tracking_category_id?, tracking_option_id?, standard_layout?, payments_only?), xero_balance_sheet (params: date?, periods?, timeframe?, tracking_option_id_1?, tracking_option_id_2?, standard_layout?, payments_only?), xero_aged_receivables (params: contact_id REQUIRED, date?, from_date?, to_date?, periods?, timeframe? -- per-contact Xero report; returns Xero report structure), xero_aged_payables (params: contact_id REQUIRED, date?, from_date?, to_date?, periods?, timeframe? -- per-contact Xero report), xero_aged_receivables_summary (params: date? -- aggregated across all contacts by paging open AUTHORISED ACCREC invoices; returns {as_at, totals:{total, current, days_1_30, days_31_60, days_61_90, days_90_plus}, contacts:[{contact_id, contact_name, total_outstanding, current, days_1_30, days_31_60, days_61_90, days_90_plus, invoice_count}]} sorted desc by total_outstanding), xero_aged_payables_summary (params: date? -- same shape as receivables summary but for ACCPAY). All date params accept both snake_case (from_date, to_date) and camelCase (fromDate, toDate). Other platforms: Slack (slack_channels, slack_users), Facebook (facebook_pages, facebook_leadgen_forms, facebook_ad_accounts), Calcom (calcom_event_types, calcom_bookings), Zoom (zoom_users, zoom_meetings), Portant (portant_templates), ActiveCampaign (activecampaign_lists, activecampaign_tags, activecampaign_automations).

**Scopes:** `integrations:read` — [full detail](./integrations/post-integrations-id-query.md)

### POST /integrations/:id/action

Execute an action on an integration (e.g. create invoice in Xero). The integration must be status "active". For xero_create_invoice and xero_create_contact_and_invoice: contact resolution is automatic -- the system finds or creates a Xero contact from the deal's linked customer or CRM contact. You do NOT need to call xero_create_contact first or set customer_id on the deal; xero_create_contact_and_invoice is now a behavioral alias for xero_create_invoice (both auto-resolve the contact). Xero invoice actions (xero_create_invoice, xero_update_invoice) support email_mode ("none" | "xero" | "trustpager"), email_subject, email_body, email_attach_pdf (boolean), email_recipient_source, email_recipient_contact_id, and email_recipient inside params. email_mode "trustpager" sends a branded Postmark email with PDF attached and a Xero pay-now link; requires a default email_config. email_mode "xero" uses Xero native /Email endpoint (no customisation). Default is "none". email_recipient_source controls which contact receives the email: "primary_contact" (deal primary contact, default), "xero_contact" (Xero contact EmailAddress), or "secondary_contact" (a specific CRM contact -- requires email_recipient_contact_id set to a crm_contacts.id). Merge tags supported in subject/body: {{xero.invoice_number}}, {{xero.due_date}}, {{xero.total}}, {{company.name}}, {{contact.first_name}}.

**Scopes:** `integrations:write` — [full detail](./integrations/post-integrations-id-action.md)
