Katkat

Fetch paginated data from two APIs

ArmadaSoftware Engineer · Technical Screen

Last updated

This question evaluates a candidate's competency in robust API retrieval, pagination handling, defensive data validation, and joining records across endpoints while preserving the order of source records and safely handling missing or malformed fields.

Write a function get_enriched_records(api_a_url, api_b_url).

api_a_url returns paginated JSON in the form:

{
 "data": [
 {"id": 1, "ref_id": "x1"},
 {"id": 2, "ref_id": "x2"}
 ],
 "next_page": 2
}

api_b_url returns paginated JSON in the form:

{
 "data": [
 {"ref_id": "x1", "target_field": "value1"},
 {"ref_id": "x2", "target_field": "value2"}
 ],
 "next_page": null
}

Implement the function so that it:

  1. Retrieves all pages from both APIs.
  2. Joins the records from the two endpoints using ref_id.
  3. Returns a list of objects in the form { "id": <id>, "target_field": <value> }.
  4. Preserves the order of records from api_a_url.
  5. Skips any record if:
  • ref_id is missing,
  • the matching record does not exist in the second API,
  • target_field is null, an empty string, or whitespace-only.
  1. Handles missing keys, empty pages, and None values safely without crashing.
  2. Uses normal HTTP request handling; assume the test harness will mock the API responses.

The focus is not on advanced algorithms, but on clean API retrieval logic, pagination handling, and defensive data validation.