Skip to content

Client & CRM sync

This guide keeps your CRM and the MendriX TMS aligned: pull client changes incrementally, and push updates back with merge-patch. It uses the Client service (clients, contacts, per-client address books and the global address book).

Step 1 — Pull changed clients (incremental)

Section titled “Step 1 — Pull changed clients (incremental)”

Use since= so each run only fetches what changed since the last run.

Terminal window
# WATERMARK is the timestamp you stored after the previous run.
curl "$MENDRIX_BASE/client/clients/?since=$WATERMARK&limit=1000" \
-H "Authorization: Bearer $MENDRIX_ACCESS_TOKEN" \
-H "Accept: application/json"
let since = loadWatermark(); // empty on first run → full load
const params = new URLSearchParams({ limit: '1000' });
if (since) params.set('since', since);
for await (const client of listAll('/client/clients/', params)) {
upsertClientInCrm(client); // your side
since = maxTimestamp(since, client.modifiedAt);
}
saveWatermark(since);

listAll is the cursor loop from Pagination & sync.

Contacts and address-book entries hang off a client:

  • GET /client/clients/{clientId}/contacts — list contacts.
  • GET /client/clients/{clientId}/addressbook — list a client’s address book.
  • GET /client/addressbook/ — the global address book.
Terminal window
curl "$MENDRIX_BASE/client/clients/CLIENT_ID/contacts" \
-H "Authorization: Bearer $MENDRIX_ACCESS_TOKEN"
curl "$MENDRIX_BASE/client/clients/CLIENT_ID/addressbook" \
-H "Authorization: Bearer $MENDRIX_ACCESS_TOKEN"

Step 3 — Push changes back (merge-patch)

Section titled “Step 3 — Push changes back (merge-patch)”

When a record changes in your CRM, patch it in MendriX. Only the fields you send change (see merge-patch).

Terminal window
curl -X PATCH "$MENDRIX_BASE/client/clients/CLIENT_ID" \
-H "Authorization: Bearer $MENDRIX_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "phone": "+31 20 123 4567", "email": "[email protected]" }'

To create clients or contacts, POST to /client/clients/ or /client/clients/{clientId}/contacts — see the reference for the request body.

  • Idempotent upserts. Key on the MendriX client id so re-processing is safe.
  • Two-way loop guard. When you write a change back, avoid immediately re-importing it as a “new” change (compare timestamps / mark the origin).
  • Watermark safety net. Persist the watermark only after a run fully succeeds; on failure the next run re-reads from the last good point.
  • Global vs per-client address book. Decide which is authoritative in your model to avoid duplicate entries.