# Apps

Mini apps your team, and your clients through their Client Portal, use inside TrustPager: a morning brief, a follow-up board, a client fact-find. Each app has versions (a draft and the live one), its own tables of data, and shares that say who can open it. Building, changing, sharing and publishing an app is for workspace admins; publishing from an AI connection waits for an admin in Approvals. Undo throws away a waiting change (discard), and any earlier version can come back as the draft (restore). Required scopes: apps:read, apps:write, apps:delete.

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

## Endpoints

### DELETE /apps/:app_id

Archive an app: it disappears for everyone and its data is kept until a workspace admin restores it (restore_app) or deletes it for good (delete_app). Workspace admins, or the maker of a personal app. Waits for approval when called by an AI connection.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id.md)

### POST /apps/:app_id/tables/attach

Give an app one of the workspace's spreadsheets as a table, under the app's own key for it (spreadsheet_id from list_app_spreadsheet_choices, which the person picked). Nothing is copied: the app reads and writes the spreadsheet itself, which stays open to the team in the Spreadsheet Builder, with the app's own rules on top. By default the app sees every sheet of it (one per opportunity, say) and each row says which record it is for; send sheet_id to use one sheet only. Every column with no key gets a readable one, kept for good. The app cannot change the spreadsheet's columns: that is done in the Spreadsheet Builder. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-tables-attach.md)

### POST /apps/:app_id/tables/attach-table

Give an app a table another app made, under the app's own key for it (table_id from list_workspace_app_tables, which the person picked). Nothing is copied: both apps work on the same rows, so what is added in one shows in the other (a leave request showing on a roster, a site measure feeding a quote). access "read" (the default) lets this app show the table and never change it; "write" lets it add, change and delete rows too. This app's own field rules sit on top (update_app_table), and it never changes the table's name, columns or who sees its rows: that is done in the app that made it. Stop using it with remove_app_table; the table and its rows stay. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-tables-attach-table.md)

### DELETE /apps/:app_id/link-passes/:pass_id

Cancel a one-tap link sent from an app (an id from list_app_links). It stops working at once, even in a page that is already open. Cancelling one that already stopped changes nothing. Workspace admins only.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id-link-passes-pass-id.md)

### POST /apps/:app_id/changes

Ask for a change to how an app looks and works: its screens, columns, pages, charts, sorting and buttons (for rows and data inside the app use add_app_rows or update_app_row instead). It takes up to two minutes and uses workspace credits. Nothing about the app changes: it answers a SUGGESTION (changed true, proposal_id, changes in plain words, access_notes to read out, preview) that a person checks. In chat the suggestion card under your reply has Preview, Keep and Undo, so tell the person to look at the preview and press Keep, and never say it is changed or live. Kept, it becomes the draft; it goes live only when an admin publishes. changed false means nothing was suggested: pass on the reply. Workspace admins only.

**Scopes:** `ai:use`, `apps:read` — [full detail](./apps/post-apps-app-id-changes.md)

### POST /apps

Create a draft app with a manifest: its views, the tables it uses and what CRM data it may read. A draft is visible only to workspace admins. Next add its tables (create_app_table), share it (share_app) and publish it (publish_app), which waits for a workspace admin. Check list_apps first so the same app is not created twice. A team member who is not a workspace admin can make a personal app instead: send template_key as one of the personal starters (no manifest) and it is ready at once, private to them and workspace admins, showing only what their role allows, five at most each.

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

### POST /apps/:app_id/audiences

Add a version of an app for a group of people (the Views and access panel): its name, whether it is for the team or for clients, the pages it shows, the TrustPager information it shows and the actions (buttons) it has. Give it to people with share_app and its audience_id. A button only works when the version has it AND the person's own role allows it. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-audiences.md)

### POST /apps/:app_id/tables

Add a table to an app: its key, name, columns and who sees which rows. At most 20 tables per app and 40 columns per table.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-tables.md)

### DELETE /apps/:app_id/permanently

Delete an app for good, straight away: the app, its versions, uploaded files, sharing and activity log are removed and cannot be brought back. Its tables and their rows stay in the workspace (list_workspace_app_tables shows them with used_by empty, and delete_spreadsheet_template removes one), except when a member deletes their own personal app: then its tables go with it. Works on a live, draft or archived app. To hide an app and keep everything, use archive_app instead. Workspace admins, or the maker of a personal app. Waits for approval when called by an AI connection.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id-permanently.md)

### DELETE /apps/:app_id/audiences/:audience_id

Remove a version of an app and every share that gives it out; the people who had it lose access unless another share gives them a version. Workspace admins only; waits for approval when called by an AI connection.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id-audiences-audience-id.md)

### POST /apps/:app_id/discard

Throw away an app's unpublished changes and go back to its live version. The draft stays in the version history as "discarded", so restore_app_version can bring it back. Nothing changes for the people the app is shared with. Refused when the app has never been live. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-discard.md)

### GET /apps/:app_id

Fetch one app with its live (published) version and manifest. Admins also get the current draft version. The access block says which views the caller has and whether they may write rows.

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

### GET /apps/kit-reference

Everything needed to write an app's files yourself with write_app_files: the rules every app follows (the same ones Evie builds by), every kit block with its exact props, notes and a real use from a finished app, the data sources and buttons an app can use, the file layout and the files of the smallest working app. Read it before writing or changing an app's files. Workspace admins only. Free read.

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

### POST /apps/:app_id/changes/:proposal_id/keep

Keep a suggestion from change_app: it becomes the app's draft (a restore point in its history). Nothing goes live until publish_app. In chat the person keeps it with the Keep button on the card instead, so only call this when they ask you to keep it. Refused when the app changed after the suggestion was made, or the suggestion is more than a day old: ask for the change again. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-changes-proposal-id-keep.md)

### GET /apps/:app_id/activity

What an app did, newest first: who opened it, rows added and changed, buttons pressed (and whether they ran or went to Approvals), and refusals. Reads are counted per person per minute. Workspace admins only.

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

### GET /apps/:app_id/audiences

The versions of an app for different people (the Views and access panel in TrustPager), for example Managers, Staff and Clients: which pages each shows, which TrustPager information it shows, which actions (buttons) it has, what it may do with the app's own tables, and who gets it. Each button also lists the automations it could set off. Workspace admins only.

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

### GET /apps/:app_id/link-passes

The one-tap links sent from an app, newest first: who each is for, the row it was sent for, what they may change, status (active, expired or cancelled), when it stops, how it was sent and how often it was opened. Filter by row_id, contact_id or status. Never shows the link itself. Workspace admins only. Free read.

**Scopes:** `apps:read` — [full detail](./apps/get-apps-app-id-link-passes.md)

### GET /apps/:app_id/shares

Who an app is shared with: everyone, a role, one person or a Client Portal, which view each gets, and whether they can add and change rows or see all rows. Workspace admins only.

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

### GET /apps/spreadsheets

The workspace's own spreadsheets (made in the Spreadsheet Builder) that an app can use as a table, so an app works on data the team already keeps instead of a new empty table. Each has its name, how many sheets and rows it holds, which kinds of record its sheets are kept on (attach_to), the columns an app would see (key, label, type, read_only; Sensitive columns are never shown to an app) and the apps already using it. Never pick one by name on your own: show the person the list and let them choose, then call attach_app_spreadsheet. Workspace admins only. Free read.

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

### GET /apps/:app_id/tables

The tables of an app with their columns (key, label, type, options, required, read_only) and who sees which rows (row_visibility: shared, own or portal_customer). source says whether the app made the table ("app") or it is one of the workspace's spreadsheets ("spreadsheet", with sheet_id: the one sheet it uses, or null for every sheet). Admins see every table; everyone else sees the tables the live version uses.

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

### GET /apps/:app_id/versions

The version history of an app (newest first) with each version's manifest and status: draft, pending_approval, published, rejected, superseded or discarded. Workspace admins only.

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

### GET /apps

List the apps in this workspace: small tools built for the team (and, through the Client Portal, for clients) that keep their own tables of data. Admins see every app including drafts; everyone else sees only the published apps shared with them. Each app says its status (draft, published, archived) and who it is for (team, portal, both). Free read.

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

### GET /apps/tables

Every app table in the workspace, whichever app it belongs to: its name, how many columns and rows it has, who sees which rows, its columns, and used_by, the apps that use it (app id, name, the key that app calls the table by, borrowed true when that app uses a table another app made, read_only when it only reads it). To let another app use one of these tables, show the person the list, let them choose, then call attach_app_table. A table outlives its app, so used_by is empty for a table whose app was deleted: those are the ones safe to delete with delete_spreadsheet_template (the id here is the template id; sheet_id is the sheet that holds its rows). Workspace admins only. Free read.

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

### POST /apps/:app_id/publish

Make the app's draft version live for the people it is shared with. It is NOT live straight away when requested by an AI connection: it waits for a workspace admin, who approves it in Approvals. Tell the person it is waiting, never that it is live. It is refused if the app has no views, lists a table that does not exist, or its views do not fit its audience.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-publish.md)

### GET /apps/:app_id/files

An app's files (its code): manifest.json, tables.json, src/main.tsx and its views, as { path: content }, from its draft, else its live version. which says which; an app with nothing saved yet answers the starter or blank app it begins from ("starting point", version_id null). Pass version_id back to write_app_files as base_version_id. Workspace admins only. Free read.

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

### DELETE /apps/:app_id/tables/:table_key

Stop an app using one of its tables. Nothing is deleted: a workspace spreadsheet stays where it is, and a table the app made stays in the App Tables tab as used by no app (delete it there if it is not needed). Pages of the app that read the table stop finding it, so update the app first. Workspace admins only.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id-tables-table-key.md)

### POST /apps/:app_id/restore

Bring back an archived app with its data, at any time. It comes back unpublished, so its admin checks it and publishes it again. An app deleted with delete_app is gone for good and cannot be restored. A personal app comes back ready to use for its maker. Workspace admins, or the maker of a personal app.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-restore.md)

### POST /apps/:app_id/versions/:version_id/restore

Bring back an earlier version of an app as its draft: that version's manifest and screen are copied into a new draft version, which goes live only through publish_app. A draft that was waiting is replaced and stays in the history. To throw away the draft and go back to the live version, use discard_app_changes instead. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-versions-version-id-restore.md)

### POST /apps/:app_id/link-passes

Send someone outside the team a one-tap link into an app, with no login: for example a subcontractor to their bookings. Name the row it is for (a booking) and its table: the link goes to the contact that row is kept for and opens the app's client page showing only rows kept for them (or name contact_id instead of a row). fields are the columns of that table they may change (for example accept or decline, sign off, hours); leave it out for look only. It never adds or deletes rows. send_by picks email, SMS or both. It stops working on expires_at (default: the latest date in the row plus 7 days, or 30 days for a contact) or when cancelled with cancel_app_link, and asks for a PIN only when the workspace's link security setting says so. The table must keep each row for a contact (row_visibility "portal_customer") and the app must be live with a client page. Answers the link (url) and how each send went. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-link-passes.md)

### POST /apps/:app_id/shares

Share an app with everyone on the team, a role, one team member or a Client Portal, optionally giving them one view of it and letting them add and change rows. An app is only visible to people it is shared with once it is published. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-shares.md)

### POST /apps/:app_id/changes/:proposal_id/undo

Throw away a suggestion from change_app. The app is not touched. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-changes-proposal-id-undo.md)

### POST /apps/:app_id/unpublish

Take a published app offline straight away. The live version goes back to being the draft and the data is kept. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/post-apps-app-id-unpublish.md)

### DELETE /apps/:app_id/shares/:share_id

Stop sharing an app with someone (remove one share). Workspace admins only; waits for approval when called by an AI connection.

**Scopes:** `apps:delete` — [full detail](./apps/delete-apps-app-id-shares-share-id.md)

### PATCH /apps/:app_id

Change an app's name, description, icon, theme colour or audience, or give it a new manifest. A new manifest only changes the draft: it goes live through publish_app. An archived app cannot be changed. Workspace admins; the maker of a personal app can change its name, description, icon and theme colour.

**Scopes:** `apps:write` — [full detail](./apps/patch-apps-app-id.md)

### PATCH /apps/:app_id/audiences/:audience_id

Change a version of an app (the Views and access panel): its name, pages, the information it shows, its actions (buttons), or what it may do with the app's tables. Takes effect for everyone who has that version within a minute. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/patch-apps-app-id-audiences-audience-id.md)

### PATCH /apps/:app_id/tables/:table_key

Change a table's name, columns or who sees which rows. For a table another app made (shared: true) or one of the workspace's spreadsheets, only this app's own field rules change (send columns with access on each), and for a shared table access "read" or "write". A change that removes a column, changes a column's type or removes a select option is refused unless confirm_drop is true, and then the stored values of the removed or retyped columns are deleted from every row.

**Scopes:** `apps:write` — [full detail](./apps/patch-apps-app-id-tables-table-key.md)

### PUT /apps/:app_id/files

Write an app's files yourself: send whole files (manifest.json, tables.json, src/main.tsx, views under src/views/) and they go through the same check and build as an Evie change, then become the app's draft (a restore point in its history; nothing goes live until publish_app). Read get_app_kit_reference first for the rules and every block's props. To change an app, read_app_files, send only the files you change with base_version_id; for a new app send every file with replace true. Refused (422) with problems listing every reason when a file breaks a rule or the app does not build, and nothing is saved: fix them all and send again. Answers the new version, changes in plain words, access_notes (data and buttons the app now uses: say them to the person) and tables_added. Use change_app instead when the person describes a change in words and wants Evie to make it. Workspace admins only.

**Scopes:** `apps:write` — [full detail](./apps/put-apps-app-id-files.md)
