Migrating existing data
When you connect a platform that already has customers and orders, load that history once. Then keep sending changes as they happen. You do not need to stop sales, freeze data or coordinate a cut-over: the CRM matches every record by platform and id, so the history and the live feed can overlap safely.
The plan#
- Connect live traffic first. Start pushing new and changed orders (or switch on pull sync) before the import starts. Nothing that happens during the import is then missed.
- Import customers, oldest first, with
POST /integrations/customers/batch. - Import orders, oldest first, with
POST /integrations/orders/batch. - Check the numbers. Compare counts and revenue with your platform (see Checking the result).
Steps 2 and 3 can be stopped and started again at any point. Records that already arrived are recognised and not duplicated.
Before you start#
- Use a separate key for the import, with the same platform name as your live key (for example both
shopify). Ask the CRM admin to raise its limit to the maximum (6000 requests per minute) and to revoke it when you are done. - Ask the admin to check Settings → Regional. Phone numbers stored without a country code are read in the tenant's default country.
- Decide about webhooks. Every imported record fires
customer.created/order.createdto subscribed endpoints. Either add webhook endpoints after the import, or have receivers skip events whoseorigin.platformis your platform. - Send real dates. Use the customer's
createdAtand the order'splacedAtandupdatedAtfrom your database. They set first-contact and purchase dates, time-based reports and which snapshot is newest. Never use "now".
Batch endpoints#
Send up to 500 items per request (body up to 10 MB). Each item has exactly the shape of the single endpoint:
POST /v1/integrations/customers/batch scope: customers.write
POST /v1/integrations/orders/batch scope: orders.write
{
"items": [
{ "externalId": "1001", "customer": { "externalId": "C-42", "fullName": "Selam Bekele", "phone": "+251911234567" }, "total": 2400, "paymentStatus": "paid", "placedAt": "2024-03-01T09:30:00Z", "updatedAt": "2024-03-04T16:00:00Z", "items": [] },
{ "externalId": "1002", "…": "…" }
]
}
The answer is always 200, with one result per item in the same order:
{
"summary": { "total": 2, "processed": 1, "accepted": 0, "failed": 1, "error": 0 },
"results": [
{ "index": 0, "externalId": "1001", "status": "processed", "orderId": "clx…", "customerId": "clx…", "created": true, "stale": false },
{ "index": 1, "externalId": "1002", "status": "failed", "code": "VALIDATION_ERROR", "message": "customer.phone: phone or email is required", "details": ["…"] }
]
}
Item status | Meaning | What to do |
|---|---|---|
processed | Saved (or already there, with duplicate: true) | Nothing |
accepted | Saved; finishing in the background | Nothing |
failed | Invalid data; see details | Fix the record and send it again |
error | Temporary problem on the CRM side | Send the item again later |
A whole request fails only when the batch itself is wrong (422: not an items array, empty, or more than 500 items), or for key, signature or rate-limit problems. A batch counts as one request against the key's rate limit, and signed requests work exactly as for single calls.
Example import script (Node.js)#
const CRM = process.env.CRM_URL; // e.g. https://api.abbaycrm.com/v1
const KEY = process.env.CRM_IMPORT_KEY;
async function sendBatch(path, items, attempt = 1) {
const res = await fetch(`${CRM}${path}`, {
method: 'POST',
headers: { 'content-type': 'application/json', 'x-api-key': KEY },
body: JSON.stringify({ items }),
});
if (res.status === 429 || res.status >= 500) {
const wait = Number(res.headers.get('retry-after')) * 1000 || Math.min(2 ** attempt * 1000, 60000);
await new Promise((r) => setTimeout(r, wait));
return sendBatch(path, items, attempt + 1);
}
if (!res.ok) throw new Error(`${path} answered ${res.status}: ${await res.text()}`);
return res.json();
}
async function migrate(kind, pages) { // pages: async iterator of arrays, oldest first
const failed = [];
for await (const rows of pages) {
for (let i = 0; i < rows.length; i += 500) {
const items = rows.slice(i, i + 500);
let { results } = await sendBatch(`/integrations/${kind}/batch`, items);
// Temporary errors: send just those items again.
for (let tries = 0; tries < 5 && results.some((r) => r.status === 'error'); tries++) {
const again = results.filter((r) => r.status === 'error').map((r) => items[r.index]);
results = (await sendBatch(`/integrations/${kind}/batch`, again)).results;
}
failed.push(...results.filter((r) => r.status === 'failed'));
}
saveProgress(kind, rows.at(-1)); // resume point, e.g. last id and updatedAt
}
return failed; // fix these and run them again
}
await migrate('customers', customersFromDb());
await migrate('orders', ordersFromDb());
Read your records in pages, ordered by updatedAt then id, so the script can resume from the last page it finished.
How the import and live orders combine#
- One record per order. An order is identified by platform +
externalId. The import and a live push for the same order update the same record. - The newest snapshot wins. A historical snapshot whose
updatedAtis not newer than what is stored is ignored (stale: true). An import that runs late can therefore never undo a live payment or delivery update. - Customers merge. A customer imported from history and the same person arriving with a live order become one profile: they match on your customer id, then phone, then email.
What happens to imported data#
- Customer totals (order count, paid revenue, first and last purchase) are rebuilt from the imported orders automatically.
- Products in order items are added to the CRM catalogue.
- If a customer already has an open sales lead in the CRM, a historical paid or delivered order moves it forward, and Delivered closes it. For a new CRM tenant there are no leads yet, so this does not matter.
- Imported orders do not create new leads or follow-up tasks for sales staff.
Checking the result#
Use the read API to compare with your own counts:
# Every order the CRM holds for your platform, page by page
curl "https://api.abbaycrm.com/v1/integrations/orders?platform=shopify&limit=200" -H "x-api-key: am_…"
The CRM admin can also open Settings → Integrations → Event log, filter by your platform and status Failed, and see every rejected record with the reason.
Without writing an import script#
If your platform offers the pull feed, you do not need a script at all. The first pull run has no saved position, so it reads everything from the beginning, about 10,000 items per run and then onwards each interval, until it has caught up. From then on it only picks up changes.