// notes · integrations

Vendor integrations as data

How adding a new API vendor became a configuration change instead of a release: the vendor's own Postman collection stored in the database, a trimmed-down runner to execute it, JSON mapping for responses, and an ordered failover chain.

The problem

Our quote flow looks up vehicle details from a registration number through third-party registry vendors. There is more than one vendor, different partner channels use different ones, and vendors change their APIs, raise prices or go down.

The usual approach is to write each vendor as code: a client class, request building, response parsing, tests and a release. Then adding or switching a vendor waits for a deploy, and during a vendor outage that is far too slow.

The observation that changed the design: many API vendors already ship a Postman collection. The request shapes, headers, auth and example bodies are already written down, in a machine-readable format. So instead of translating the collection into code, we store it and run it.

The shape of a vendor record

A vendor is a database row holding JSON, editable from the internal admin:

{
  "custom_items": {
    "registration_no_variable": "reg_no",
    "registration_no_delimiter": "-"        // MH-12-AB-1234
  },
  "map": {
    "QUOTE": {
      "title": "Get RC details",
      "variables": { "UAT": {...}, "PROD": {...} },
      "response_parser_helper": {
        "response_drill": "result.data",
        "response_success_attribute": "status",
        "response_success_status": "OK",
        "response_not_found_code": "NOT_FOUND"
      }
    }
  }
}

Small vendor quirks live in that config too: whether the registration number is sent as MH12AB1234, MH-12-AB-1234 or MH 12 AB 1234, and which variable receives the end user's IP when a vendor asks for it.

The runner: a trimmed copy of postpy2

To execute collections I started from postpy2, a small open-source library that loads a Postman collection and exposes each request as a Python call. Then I took things out.

The library was written for developers running their own collections on their own machine. Here the collection is configuration that admins can edit in production, so every feature is attack surface. The copy we run:

One small guard earned its place: before sending, the runner checks the final URL and refuses to send if any {{variable}} is still unreplaced. A typo in a variable name fails loudly instead of calling a half-built URL.

The trimmed copy is vendored into the codebase rather than installed as a package. Because the changes remove features, that has a useful side effect: an upstream release can never quietly bring a removed feature back.

Turning responses into outcomes

Every vendor reports success and failure differently: HTTP status codes, a status string in the body, an error code buried two levels down. The map's response helper turns each response into one of a few outcomes:

OutcomeMeaningWhat happens next
SUCCESSVehicle found and parsedMapped to internal fields and stored
NOT_FOUNDVendor answered: no such vehicleLogged, so that vendor is not asked again soon; the next vendor in the chain is tried
API_DOWNNo usable responseNext vendor in the chain
UNKNOWN_RESPONSEResponse did not match the mapNext vendor in the chain; worth a look

Every call is logged with the vendor, lookup type, HTTP status, response headers, raw response and outcome. A decorator also records where the call came from (the calling function and file) and, when there is a request, the end user's IP and user agent. When a vendor disputes a bill or a partner reports a wrong vehicle, the answer is one query away.

Not paying twice

Vendors charge per call, so the cheapest call is the one you do not make:

Caching NOT_FOUND matters as much as caching success: a mistyped or fake number would otherwise be paid for every time someone retries it.

Failover as an ordered list

Because a vendor is just a row, failover is just an ordered list of rows. Each lookup type has a priority list of vendors; a lookup walks the list and returns the first success:

def lookup_with_fallback(lookup_type, reg_no):
    response = None
    for vendor in vendor_chain(lookup_type):  # admin-ordered
        response = call_vendor(vendor, lookup_type, reg_no)
        if response.success:
            return response
    return response  # the last failure

Reordering vendors, or adding a new one at the end of the chain, is an admin change with no deploy. Each lookup type has its own chain, so each can prefer a different vendor.

The trade-offs

What I would add next

A runner that executes admin-editable configuration should enforce limits the configuration cannot override:

Takeaways