Fetch paginated data from two APIs
ArmadaSoftware Engineer · Technical ScreenLast 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:
- 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_idis missing,- the matching record does not exist in the second API,
target_fieldisnull, an empty string, or whitespace-only.
- Handles missing keys, empty pages, and
Nonevalues 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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.