Reading & changing data
Import api, ui and server from @zuperpro/app-sdk, or use the hooks. For jobs, customers, invoices and quotes, use api.records: it is typed and needs no paths.
api.records
Record types are named like extension objects: 'job', 'customer', 'invoice', 'quote'. Zuper's API calls quotes "estimates", so quote fields start with estimate_.
| Call | Resolves with |
|---|---|
api.records.get('job', uid) | The record, typed (JobRecord, CustomerRecord, InvoiceRecord, QuoteRecord). Common fields are typed; every other field Zuper returns is there as unknown. |
api.records.list(type, { filter, search, limit, cursor, sortBy, sort }) | One page: { records, next, previous, hasMore }. Pass next as cursor for the next page. limit is 1–100, default 25. |
api.records.create(type, data) | What Zuper answers: the whole record, or only its uid on some types |
api.records.update(type, uid, data) | Changes fields. It doesn't change a status, and on a recurring job it changes only that job. |
api.records.delete(type, uid) | Nothing |
Filters
A filter value matches records with that value; a list matches any of them. Only these keys are allowed, and any other key rejects the call before anything is sent:
| Record type | Filter keys |
|---|---|
job | status_type ('NEW', 'SCHEDULED', 'COMPLETED' …), status_uid, customer_uid, job_category_uid, job_priority |
customer | is_active (one true/false value) |
invoice | invoice_status ('DRAFT', 'PAID' …), customer_uid, job_uid |
quote | estimate_status ('DRAFT', 'APPROVED' …), customer_uid, job_uid |
const page = await api.records.list('job', { filter: { status_type: ['NEW', 'SCHEDULED'] }, search: 'Acme', limit: 10 });
const more = page.hasMore ? await api.records.list('job', { filter: { status_type: ['NEW', 'SCHEDULED'] }, cursor: page.next! }) : null;Other host calls
| Call | What it does |
|---|---|
api.get(path, query?), api.post(path, body?), api.put, api.patch, api.delete(path), api.request({ method, path, query, body }) | The Zuper REST API, for anything api.records doesn't cover, such as status changes. Paths are relative, such as '/jobs/' + job.recordId. Put query parameters in query, not in the path. |
ui.toast(message, { tone }) | tone is 'success', 'error' or 'info' |
ui.confirm({ title, description?, confirmLabel? }) | Resolves to true or false |
ui.openDialog(dialogId, { input }) | Opens one of your dialogs. See Dialog |
server.invoke<typeof fn>(name, input) | Calls one of your server functions |
Permissions
Every api call runs as the signed-in user, so it can do exactly what that user can do in Zuper, no more. There are no app scopes to declare. A call the user isn't allowed to make rejects with the Zuper API's error.
Loading data
Load data in useEffect. Show Text variant="muted" while it loads, and catch errors, because a host call rejects with an Error.
import { api, type JobRecord } from '@zuperpro/app-sdk';
const [job, setJob] = useState<JobRecord | null>(null);
const [error, setError] = useState('');
useEffect(() => {
api.records.get('job', record.recordId).then(setJob, (e: Error) => setError(e.message));
}, [record.recordId]);Updated about 1 hour ago
