Fetch and parse JSON from REST API
Company: Motive
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Onsite
##### Question
Set up a minimal coding environment from scratch and write runnable code that fetches and processes data from a REST API. You are given an endpoint that returns a JSON payload (for example, fleet/courier tracking records with fields such as `order_id`, `courier_id`, `latitude`, `longitude`, and `timestamp`). Perform an HTTP GET against the endpoint, parse the response, extract the specified fields, and produce the required output. Walk the interviewer through your approach as you go.
Your solution should address all of the following:
1. **HTTP integration.** Perform the HTTP GET and parse the JSON response. Handle authentication (e.g., bearer token / API key).
2. **Robustness.** Handle pagination, rate limiting (backoff/retry with exponential backoff), request timeouts, and malformed or partial records without crashing the run.
3. **Field extraction & transformation.** Extract the specified fields and transform the records into the required target schema.
4. **Output #1 — serialized records.** Output the transformed records as CSV and/or JSON.
5. **Output #2 — aggregation.** Compute aggregates per category and return the top-k items.
6. **Quality.** Include basic unit tests, plus error handling and logging.
7. **Analysis.** Explain your approach, the edge cases you considered, and the time/space complexity of your solution.
Overview: A Motive Software Engineer onsite coding exercise: build a small, resilient script from scratch that performs an authenticated HTTP GET against a paginated REST API, parses the JSON, extracts and transforms records, and produces both serialized CSV/JSON output and per-category top-k aggregates. It evaluates HTTP/REST integration, rate-limit and retry handling with backoff, timeouts, malformed-record handling, unit testing, logging, and complexity analysis.