> ## 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.

# Connect the customer source

> Declare the CRM operations as targets from its OpenAPI contract and read its accounts with a feed

> [!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.

Begin in `examples/openapi-crm` in the prepared source checkout described in
[Before you begin](https://docs.bijection.com/start/tutorial#before-you-begin).

## Declare the receiver

`bijection/crm.ts` writes the CRM as a `receiver` from
`@bijectionhq/bijection`: a subtree of targets over one shaped HTTP
API, one `operation` per `operationId` of the contract. The wire schema
cannot say what the service promises about a repeated request, so the
receiver's `contract` states it: the CRM deduplicates by `Idempotency-Key`,
which carries the task's `once`, for a day.

```ts bijection/crm.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { env, secret, t } from "@bijectionhq/bijection";
import { operation, receiver } from "@bijectionhq/bijection";
import { crm } from "./roles";

/** `components.schemas.Customer`. */
const customer = { externalId: t.string, name: t.string, email: t.string, revision: t.string };

/** The CRM's service token: a bearer token code never holds. */
export const token = secret();

export const api = receiver({
  endpoint: env("CRM_URL", "https://crm.example.com"),
  hosts: ["crm.example.com"],
  auth: { kind: "bearer", secret: token },
  label: crm,
  delivery: { timeout: { seconds: 30 } },
  operations: {
    getIdentity: operation({
      method: "GET",
      path: "/identity",
      args: {},
      returns: { accountId: t.string, incarnation: t.string },
      within: { seconds: 30 },
    }),
    listCustomers: operation({
      method: "GET",
      path: "/customers",
      args: { after: t.maybe(t.string) },
      returns: { items: t.array(customer), next: t.maybe(t.string) },
      within: { seconds: 30 },
      request: ({ after }) => ({ body: after === null ? {} : { after } }),
    }),
    renameCustomer: operation({
      method: "PATCH",
      args: { customerId: t.string, revision: t.string, name: t.string },
      returns: t.json,
      within: { days: 1 },
      request: ({ customerId, revision, name }) => ({
        path: `/customers/${encodeURIComponent(customerId)}`,
        headers: { "If-Match": revision },
        body: { name },
      }),
      answer: { statuses: [412] },
    }),
  },
});
```

The tree places the token and the operations at `crm`, so the secret's path
is `crm.token` and the rename target is `crm.renameCustomer`. Code never holds
the token. Set it once after the first deploy:

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

A service that takes one JSON `POST` at one fixed URL needs no receiver:
`target({ via: http(url, { bearer }), args, returns, within })` declares it
directly. [Effects](https://docs.bijection.com/functions/effects.md) covers targets and performers.

## Read the accounts

The `customers` feed of the sources library reads `listCustomers` from its
`after` cursor every minute and lands each page into the `accounts` table,
together with its cursor, in one commit. A list's end proves no deletion, so
nothing is removed. The feed's passes are the library's own continuations,
which run as the installation under `crm`. Writers operate the feed
(`feed.control.refresh`, `pause`, `probe`); readers see its health
(`feed.health.list`). See `crmFeed` in `bijection/crm.ts` and the
[connector catalog](https://docs.bijection.com/reference/connectors) for packaged providers.

Continue to [define customers](https://docs.bijection.com/start/tutorial/define-customers.md).


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