# Tracing IDs

## At a glance: how Aiwyn records connect

If you only look at one thing on this page, make it this map. The client sits at the center: almost every record points back to one, so from any record you can find its client and get to everything else from there.

Each arrow points from a record to the record one of its fields identifies. Dashed lines link records that can have many of each other. 

In the API, a project is sometimes called a **job**, so a project's ID appears as `jobId` on related records. Engagements relate to projects too: an engagement lists the projects it covers, and an engagement event carries their IDs. An engagement document points to its file through `fileId`.

## Overview

Every automation eventually runs into the same question: which record in Aiwyn is the same as this record in my other system? Aiwyn and your other systems each number clients, projects, and engagements in their own way, so it takes a little planning to connect them reliably. This guide helps you do that.

The key ideas:

- **Every Aiwyn record has an Aiwyn ID** that never changes. It is the safest thing to store.
- **Many records also carry your other systems' references**, such as a practice-management client number.
- **You decide where the match lives.** Keep a lookup between Aiwyn IDs and the other system's IDs in your own storage, or store your system's reference on the Aiwyn record itself.
- **Records link to each other by ID.** From an engagement you can reach its client, its projects, and its documents.


Below, you'll find the identifiers Aiwyn uses, the most common paths from an event to the data you need, and a simple way to keep your records matched.

## The kinds of identifier

| Identifier | What it is | Example | Use it for |
|  --- | --- | --- | --- |
| `id` | Aiwyn's own ID for the record. Unique within your firm's Aiwyn, and different between sandbox and production. IDs are numbers, and an invoice is identified by its AR transaction ID, `arTranId`. | `34567` | Your lookup table, API calls by ID, webhook `entityId` |
| Foreign IDs (`clientId`, `jobId`, `engagementId`, …) | The Aiwyn `id` of a related record | `"clientId": 1001` | Following one record to another |
| `pmsRef` | The record's reference in your practice-management system, where Aiwyn's data came from one. Opaque text. | `"8842"` | Matching to that system |
| `clientRef`, `jobRef`, `invoiceNumber` | Human-facing references staff see on screen | `"45123"` | Display and search; a fallback for matching |
| `systemRef` | A pair you send on create-or-update calls: `{"system": "<your label>", "reference": "<its ID>"}` | `{"system": "VENDOR", "reference": "37584"}` | Making writes safe to retry; pointing at a related record by your own reference |
| `sysRefs` | The `systemRef` values stored on a record | `{"VENDOR": {"ref": "37584"}}` | Seeing which external references a record carries |


Two `system` labels are reserved. `"PM"`, in capitals, matches a record's `pmsRef`. `"aiwyn"` matches a record's Aiwyn `id` in the top-level `systemRef` of a write; in fields such as `clientId`, send the Aiwyn ID as a number instead. Any other label is yours: Aiwyn stores it in the record's `sysRefs` and matches on it, exactly as written, the next time you send it. For time and expense entries and codes, a `systemRef` that matches nothing also falls back to an entry or code whose `pmsRef` equals its `reference`.

Two rules of thumb that will save you headaches:

- **Store the Aiwyn `id`** as the key in your lookup table. Human-facing references can be edited, reused, or formatted differently.
- **Never mix environments.** An ID from the sandbox means nothing in production, and the reverse.


When creating or updating time and expense entries, fields such as `clientId`, `jobId`, and `taskId` accept either an Aiwyn ID or a `systemRef`. If your practice-management references are already on the client or project in Aiwyn, you can point at them directly with `"system": "PM"`.

## Tracing from what you have to what you need

Here are the paths automations take most often. Each step is a single API call, and the [API reference](/bundle) has the exact endpoint for each one. Where a full walkthrough exists, it's linked below the steps.

**From a signed engagement to a document's consent outcome**

1. The webhook's `entityId` is the engagement's Aiwyn ID.
2. Get the engagement's documents by engagement ID. Each consent document has a type and an `affirmativeStatus`: `AFFIRMATIVE`, `NEGATIVE`, `INDETERMINATE` (a signer has agreed, and others still have to answer), or `EMPTY` (no signer has answered yet). Act only on the first two. For a `ONE_SIGNATURE_REQUIRED` document, `affirmativeStatus` doesn't apply the one-signature rule: any decline makes it `NEGATIVE`, and an agreement while other signers haven't answered makes it `INDETERMINATE`. Rely on the `CONSENT_RECORDED` event for those documents.
3. Get the engagement by ID for its `clientId`; get the client for its references.
4. Use your lookup to find the client in the other system.


Full walkthrough: [Tracking client consent](/guides/track-client-consent).

**From a charge in another system to an expense in Aiwyn**

1. Take the other system's client (and, if it has one, project) ID from its event.
2. Use your lookup to find the Aiwyn client `id` and project `id`.
3. Confirm both are active; entries against an inactive client or project, or a project that belongs to a different client, are rejected.
4. Create the expense entry with that client and project, an expense code that exists in Aiwyn, and the other system's charge ID as the `systemRef`.


**From a payment to the invoice it paid**

1. The payment carries the numbers of the invoices it paid (`invoice_numbers`) and its client's reference (`client_ref`).
2. Search invoices by `invoiceNumber`, and clients by `clientRef`.


**From a project to its work**

1. Search tasks, or WIP (which holds time and expense entries), filtered by the project's `id` (`jobId`). WIP search returns only active records by default, and your own `where` replaces that default, so add `"isActive": { "_eq": true }` to keep it.


If there's a path you need that the API doesn't cover yet, let your Aiwyn contact know.

## Matching Aiwyn records to another system

The simplest approach is a lookup table that records which Aiwyn record matches which record in the other system. It can be a database table, a spreadsheet your automation reads, or the automation platform's own storage. A minimal one for clients:

| Aiwyn client `id` | Other system's client ID | Matched on | Last checked |
|  --- | --- | --- | --- |
| `1001` | `C-1042` | Practice-management reference | 2026-11-02 |


If you would rather keep the match in Aiwyn, store your system's client ID on each Aiwyn client as a client custom field: every client read returns it in `customFieldValues`. A `systemRef` also works for matching your writes, but client reads only return the `PM` one, as `pmsRef`. [Tracking client consent](/guides/track-client-consent#match-aiwyn-clients-to-your-system) shows the custom-field approach.

**Building it the first time**

1. Export clients from Aiwyn (list clients) and from the other system.
2. Match on a reference both share, such as the practice-management client number stored as `pmsRef` in Aiwyn.
3. Have someone at the firm review anything that didn't match. Try not to match on name alone, since names repeat and change.


**Keeping it current**

- Add new clients as they appear, either from a client-created webhook if your firm has one enabled, or with a scheduled job that searches for clients updated since the last run.
- Re-check the table periodically for clients that were merged, renamed, or made inactive.


**When there is no match**

If your automation can't find a match, it's best not to guess. Log the record, let the automation's owner know, and leave it for a person to sort out. Writing data to the wrong client is much harder to undo than a short delay.

The same approach works for projects and engagements: store the Aiwyn `id` against the other system's ID, and decide in advance what counts as the same record when one side has more records than the other (for example, one Aiwyn client covering several entities in the other system).

## Related guides

- [Building automations](/guides/building-automations): the overview, and what your firm owns.
- [Using the API](/guides/using-the-api): reading records by ID and writing with `systemRef`.
- [Using the webhooks](/guides/webhooks): the IDs each event carries.
- [Data dictionary](/reference/data-dictionary): every field on every record.