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:
-
Retrieves
all pages
from both APIs.
-
Joins the records from the two endpoints using
ref_id
.
-
Returns a list of objects in the form
{ "id": <id>, "target_field": <value> }
.
-
Preserves the order of records from
api_a_url
.
-
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.
-
Handles missing keys, empty pages, and
None
values safely without crashing.
-
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.