Rana Maninder Singh
Lesson 7 of 12API & Integration Development

ERP Integrations

Lesson opener

In one line: An ERP integration copies a named master or posts a named transaction. It does not silently merge two truths.

Why it matters: Northline's webshop created a customer the ERP already had, because the match used the display name. "Harbour Tools" and "Harbour Tools Pvt Ltd" became two accounts. Invoices split, and credit control saw only half the balance.

Before this lesson: Consuming APIs.

What you will be able to do

Prerequisites

Lessons 1 to 6. No particular ERP product is required. Field names below are Northline's illustrative contract, not a universal schema for SAP, Oracle, or any other product.

Five flows

FlowSystem of recordWhat movesWhat must not happen
Customer syncERP accountaccount id, name, order block, payment termsA second account because the name differed
Supplier syncERP suppliersupplier id, name, payment termsBank details copied into a system whose role forbids them
Inventory syncWarehousesku, on-hand, as-of timeThe webshop overwriting the warehouse count
Sales integrationERP sales orderorder id, account id, linesA second order when the webshop retries
Procurement integrationERP purchase orderorder id, supplier id, linesA receipt posted against the wrong order

The match key is the identifier the system of record already issued (account_id, supplier_id, sku, order_id). A name is a label. Names collide.

When both sides changed the same field after the last successful sync, the job stops on that record and raises a conflict for a person. It does not pick the newer timestamp unless the owner has signed that rule. A timestamp is evidence. It is not automatically the decision.

Sales and procurement posts use the idempotency rule from lesson 2. The webshop order number is stored on the ERP order so a repeat finds the original.

def match_customer(incoming_name, erp_rows):
    hits = [row for row in erp_rows if row["name"].casefold() == incoming_name.casefold()]
    return hits


def sync_decision(local_version, remote_version, last_synced_version):
    local_changed = local_version != last_synced_version
    remote_changed = remote_version != last_synced_version
    if local_changed and remote_changed:
        return "conflict"
    if remote_changed:
        return "take_remote"
    if local_changed:
        return "send_local"
    return "unchanged"


erp = [
    {"account_id": "C-1044", "name": "Harbour Tools"},
    {"account_id": "C-1090", "name": "Harbour Tools Pvt Ltd"},
]
assert len(match_customer("Harbour Tools", erp)) == 1
assert sync_decision(2, 3, 1) == "conflict"
assert sync_decision(1, 3, 1) == "take_remote"

Name matching is shown here so you can see the collision. The integration must not create an account from a name match of one row. It asks for account_id.

Teacher walkthrough: customer and stock

Illustrative.

  1. Webshop has a checkout for account id C-1044. It does not search by name.
  2. ERP returns order_block: false, payment_terms_days: 30.
  3. Warehouse GET for FX-100 returns on_hand: 80, as_of: "2026-09-30T08:00:00+05:30". The webshop displays 80 and the time. It does not write 80 back.
  4. A sales order POST carries webshop id W-501 and one line, SKU FX-100, quantity 2. The ERP returns ERP order S-8801. A repeat POST with W-501 returns S-8801 again.
  5. Validation: one ERP account, one ERP order, and the warehouse quantity unchanged by the webshop.

A second workplace case

Procurement creates a purchase order in the ERP and expects the supplier portal to show it. The portal is a copy. The receipt is posted only in the ERP, against that purchase order id. A receipt that arrives with no purchase order id is rejected. It is not "received into a suspense pile" by this course's contract, because Northline has not signed a suspense process.

Failure example: last write wins on payment terms

Symptom: Credit set terms to 30 in the ERP. Sales set 45 in the CRM a minute later. The sync wrote 45 into the ERP because the CRM timestamp was newer. Invoices changed.

Diagnosis: Both sides changed the field. The job treated the clock as the owner. The root cause is a missing conflict rule. The ERP is the system of record for payment terms.

Correction: Stop on that account. Show both values to the ERP owner. Write 45 only if that owner accepts it. Do not let the CRM push terms.

Validation: After the conflict, the ERP still says 30 until the owner changes it. The sync log says conflict for C-1044.

Guided practice: three records

Scenario: Last synced version is 1 for every row. Figures are illustrative.

RecordERP versionOther system version
Customer C-1044 terms14
Supplier S-9 name21
Item FX-100 on-hand in the webshop55

The webshop is not the system of record for on-hand.

Hints:

Complete solution:

Customer terms: ERP version 1 equals last sync, the other system is 4, so take_remote would apply only if the other system were allowed to own terms. It is not. The job ignores the CRM value and does not call it a conflict with the ERP's unchanged record. If the CRM must display 30, it takes the ERP value. Supplier name: ERP changed (2) and the other system did not, so send_local if that system is a copy of the name. Item on-hand: the webshop must not send a quantity. The warehouse remains the source. The webshop reads it. Validation: terms stay at the ERP value, the supplier name update has one direction, and no webshop write hits stock.

Independent practice

Describe one ERP flow you know, or Northline's sales order.

Acceptance criteria:

Common mistakes

  • Matching customers on name.
  • Letting the webshop write the warehouse on-hand figure.
  • Last-write-wins on a field the ERP owns.
  • Posting a receipt that has no purchase order id "so the goods are visible."

Quick check

  1. What is the match key for a Northline customer sync?
  2. Why did "Harbour Tools" and "Harbour Tools Pvt Ltd" become a defect?
  3. Who may update on-hand?
  4. What does the job do when both sides changed payment terms?
  5. What ties a retried webshop order to one ERP order?

Answers:

  1. account_id, issued by the ERP.
  2. They are two names. A name match does not prove one account.
  3. The warehouse system. The webshop reads a copy.
  4. It stops and asks the ERP owner. It does not pick the later clock.
  5. The webshop order id stored on the ERP order, so the repeat finds S-8801 instead of creating another.

Lesson summary

Sync masters on the system of record's identifier. Copy stock in one direction. Post sales and procurement documents once. When both sides change an owned field, stop and ask the owner.

Bridge to the next lesson

The sales order was a pull: the webshop called the ERP. The next lesson is the other pattern, where the ERP pushes an event to a webhook when something changes.