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.
# 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 loadconst 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.
- Schedule Trigger — run every few minutes.
- HTTP Request
Get access token— the login node from Using n8n (Custom Auth =MendriX API token). - HTTP Request (
GET /client/clients/):Authorizationheader =Bearer {{ $('Get access token').first().json.data.items[0].access }}; querylimit=1000andsince={{ $json.watermark }}(read the stored watermark from a previous step / data store). - Enable Pagination to follow the cursor (see Using n8n).
- Split Out / Loop the returned items and map fields to your CRM.
- Store the newest
modifiedAtas the next watermark.
Importable workflow: client-crm-sync.json.
Step 2 — Sync contacts & address book
Section titled “Step 2 — Sync contacts & address book”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.
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"Add HTTP Request nodes per client id (from Step 1), or use a Loop over the
client list feeding clientId into the URL, e.g.
/client/clients/{{ $json.id }}/contacts.
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).
curl -X PATCH "$MENDRIX_BASE/client/clients/CLIENT_ID" \ -H "Authorization: Bearer $MENDRIX_ACCESS_TOKEN" \ -H "Content-Type: application/json" \To create clients or contacts, POST to /client/clients/ or
/client/clients/{clientId}/contacts — see the
reference for the request body.
- HTTP Request node, Method
PATCH, URL/client/clients/{{ $json.id }}. - Body Content Type:
JSON; send only the changed fields. - Header
Content-Type: application/json.
Making sync robust
Section titled “Making sync robust”- 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.