Skip to main content
The Customers API provides endpoints for managing customer records, including CRUD operations, enrichment, portal access, and invoice summaries.

Query Endpoints

get

Retrieve a paginated list of customers.
q
string
Search query for customer name, email, or website
sort
array
Array of sort objects
limit
number
Number of results per page
import { trpc } from '@/lib/trpc';

const { data, meta } = await trpc.customers.get.query({
  q: 'acme',
  limit: 20,
});

getById

Retrieve a specific customer by ID.
id
string
required
Customer UUID
customer
object
const customer = await trpc.customers.getById.query({
  id: 'customer-uuid',
});

getInvoiceSummary

Get invoice summary statistics for a customer.
id
string
required
Customer UUID
summary
object
const summary = await trpc.customers.getInvoiceSummary.query({
  id: 'customer-uuid',
});

getByPortalId

Public endpoint - no authentication required
Retrieve customer information using their portal ID (for customer portal).
portalId
string
required
The customer’s unique portal ID
data
object
const { customer, summary } = await trpc.customers.getByPortalId.query({
  portalId: 'unique-portal-id',
});

getPortalInvoices

Public endpoint - no authentication required
Get invoices for a customer via their portal.
portalId
string
required
The customer’s unique portal ID
cursor
string
Pagination cursor
pageSize
number
Number of results per page
data
object

Mutation Endpoints

upsert

Create a new customer or update an existing one.
id
string
Customer UUID (for updates, omit for new customers)
name
string
required
Customer name
email
string
Email address
phone
string
Phone number
website
string
Website URL
address
object
Address object
vatNumber
string
VAT/tax ID number
note
string
Internal notes
customer
object
The created or updated customer object
// Create new customer
const customer = await trpc.customers.upsert.mutate({
  name: 'Acme Corporation',
  email: '[email protected]',
  website: 'https://acme.com',
  address: {
    line1: '123 Main St',
    city: 'New York',
    state: 'NY',
    zip: '10001',
    country: 'US',
  },
});

// Update existing customer
const updated = await trpc.customers.upsert.mutate({
  id: 'existing-uuid',
  email: '[email protected]',
});
When creating a new customer with a website, AI enrichment is automatically triggered to fetch additional company information.

delete

Delete a customer.
id
string
required
Customer UUID
await trpc.customers.delete.mutate({
  id: 'customer-uuid',
});

togglePortal

Enable or disable customer portal access.
customerId
string
required
Customer UUID
enabled
boolean
required
Whether to enable or disable portal access
customer
object
Updated customer object with portalId if enabled
// Enable portal access
const customer = await trpc.customers.togglePortal.mutate({
  customerId: 'customer-uuid',
  enabled: true,
});

console.log('Portal URL:', `https://app.midday.ai/portal/${customer.portalId}`);

// Disable portal access
await trpc.customers.togglePortal.mutate({
  customerId: 'customer-uuid',
  enabled: false,
});

AI Enrichment

enrich

Manually trigger AI enrichment for a customer.
id
string
required
Customer UUID
data
object
await trpc.customers.enrich.mutate({
  id: 'customer-uuid',
});
Enrichment requires the customer to have a website. The AI will fetch company information like logo, description, industry, and social media links.

cancelEnrichment

Cancel an in-progress enrichment job.
id
string
required
Customer UUID
await trpc.customers.cancelEnrichment.mutate({
  id: 'customer-uuid',
});

clearEnrichment

Clear enrichment data for a customer.
id
string
required
Customer UUID
await trpc.customers.clearEnrichment.mutate({
  id: 'customer-uuid',
});

Customer Portal

The customer portal allows your clients to view their invoices and payment status without logging into your system.

Enabling Portal Access

// 1. Enable portal for a customer
const customer = await trpc.customers.togglePortal.mutate({
  customerId: 'customer-uuid',
  enabled: true,
});

// 2. Share the portal URL with your customer
const portalUrl = `https://app.midday.ai/portal/${customer.portalId}`;

// 3. Customer can access their invoices without authentication

Portal Features

  • View all invoices (paid, unpaid, overdue)
  • Download invoice PDFs
  • See payment status and history
  • View invoice summaries and totals
  • No login required - access via unique secure link

Build docs developers (and LLMs) love