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

# How syncing works

> The create-or-replace model behind the business and customer sync endpoints

The syncing endpoints are designed to treat your business and customer data as
the source of truth. If you have a unique identifier for business or customer
within your vertical software, you can provide that as the `external_id` on
every request and Pocketflows will create or update the record to match and
return the Pocketflows ID as well.

There are four sync endpoints:

* `POST /sync/businesses`
* `POST /sync/businesses/batch`
* `POST /sync/businesses/:business_id/customers`
* `POST /sync/businesses/:business_id/customers/batch`

For the requests to send, see
[Sync businesses and customers](https://docs.pocketflows.com/how-to/sync-businesses-and-customers.md).

## Create or replace

All of the sync endpoints adopt a "create or replace" strategy. When
`external_id` is provided in the API payload, if no existing record is found
with the `external_id`, a new record is created. When an existing record is
found, then its properties are wholly replaced by the new ones.

> [!NOTE]
>
> This also blanks out properties that are not provided in the request, so it is important to pass
> all properties in every sync request.

## `id` and `external_id`

The sync endpoints allow either `external_id` or `id` (the Pocketflows ID) to be
passed. `id` takes precedence over `external_id` and will be used to find the
record. When both `id` and `external_id` are passed, the record is first found
via the `id` then the `external_id` is updated to whatever is passed (along with
all other fields)

## Batch requests

The customer batch endpoint allows for partial success: when a customer record
is invalid for whatever reason, the rest of the request will process and create
/ replace the other records synced.

The business batch endpoint does not: if any record is invalid, for example an
`id` that does not match one of your businesses, the whole request fails and no
businesses are synced.

## Related

* [Sync businesses and customers](https://docs.pocketflows.com/how-to/sync-businesses-and-customers.md) for
  step-by-step requests.
* [Migrate to the sync endpoints](https://docs.pocketflows.com/how-to/migrate-to-sync-endpoints.md) if you
  currently use the previous business and customer creation and update
  endpoints.


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