> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Customer account workflow

> Connect observed CRM accounts to local customers and follow an external rename

> [!NOTE]
>
> These examples describe the current Bijection CLI and SDK source. Use builds
> from the same source commit for these APIs. The public CLI and npm SDK
> are published independently and may lag this reference.

The [OpenAPI CRM application](https://github.com/bijectionhq/bijection/tree/main/examples/openapi-crm)
follows one customer through a source feed, a labelled table, roles and a
durable rename.

## Application map

| Source | Responsibility |
| - | - |
| `services/crm/openapi.yaml` | The wire contract: identity, the change list and the rename |
| `bijection/crm.ts` | The `crm` receiver, its `crm.token` secret and the `customers` feed |
| `bijection/schema.ts` | Observed `accounts` and local `customers`, both under the `crm` label |
| `bijection/customers.ts` | `associate`, `rename`, its continuation `renamed`, and the reads |
| `bijection/roles.ts` | The `crm` label and the `reader`, `writer` and `admin` roles |

## Prepare and run

Deploy against a service that implements the committed contract. The
example holds the contract and its receiver, not a running CRM. Set the
receiver's credential once:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
printf %s "$CRM_SERVICE_TOKEN" | bijection secret set crm.token
```

Once the feed has read the accounts:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection list data.accounts --first 20
bijection mutate customers.associate account="$CRM_ACCOUNT_ID" label=Acme --once associate-acme
bijection query customers.directory
bijection mutate customers.rename customer="$CUSTOMER_ID" name='Acme Europe' --once rename-acme-europe
```

`associate` answers the customer's key; use it as `CUSTOMER_ID`. `rename`
commits the requested name and one `renameCustomer` task together, with
`once` set to the customer, the revision read and the name, so asking again
sends nothing more. The receiver's contract is `keyed`: a send whose answer
was lost is resent under the same `Idempotency-Key`, and the CRM answers
with the original rename.

## Read the result correctly

`requested_name` is the name a writer asked for, and `rename.status` is how
the CRM answered, recorded by the continuation `customers.renamed`:
`applied`, `conflict` (the account moved: read it again and retry),
`pending`, `rejected`, `unknown` or `failed`. A refused task keeps its
code and message in `rename.refusal`. Display it using `refusalText` from
`@bijectionhq/bijection/client`. `observed_name` changes only
when the feed reads the account back, so a concurrent change in the CRM
may differ from the request.

To explore privately, stage changes in a [branch](https://docs.bijection.com/branches): tasks staged
there are never performed. Discard the branch when you are done.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.