Consume an API and convert to CSV file.
Asked in the technical interview stage. Practical coding task in the Andela technical interview.
Implement a deterministic, testable version without making network requests. The input is an ordered list of API page objects, each containing an items array of flat JSON records. Return one CSV string. Build the header from keys in first-seen order across all records, leave missing values empty, and correctly escape commas, quotes, and newlines using standard CSV rules.
Signature: def api_pages_to_csv(pages):
Output: A CSV string with one header row and one row per record. Use line endings and return an empty string when there are no records.
def api_pages_to_csv(pages):