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.
Search query for customer name, email, or website
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.
Whether customer portal access is enabled
Unique portal ID for customer access
Status of AI enrichment: “pending” | “completed” | “failed”
const customer = await trpc . customers . getById . query ({
id: 'customer-uuid' ,
});
getInvoiceSummary
Get invoice summary statistics for a customer.
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).
The customer’s unique portal ID
Customer object with limited fields
Invoice summary for this customer
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.
The customer’s unique portal ID
Number of results per page
Pagination metadata with cursor
Mutation Endpoints
upsert
Create a new customer or update an existing one.
Customer UUID (for updates, omit for new customers)
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.
await trpc . customers . delete . mutate ({
id: 'customer-uuid' ,
});
togglePortal
Enable or disable customer portal access.
Whether to enable or disable portal access
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.
Whether the enrichment job was queued successfully
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.
await trpc . customers . cancelEnrichment . mutate ({
id: 'customer-uuid' ,
});
clearEnrichment
Clear enrichment data for a customer.
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