Fetch Paginated API Data and Store in SQLite Database
Beginner Mode

Start your terminal to use beginner mode.

Scenario

A REST API provides product inventory data in JSON format with nested structure and pagination. You need to fetch all data, transform it into a flat structure, and store it in a database.

Task

Write a Python script at /home/interview/fetch_inventory.py that fetches all paginated product data from http://api.inventory.local/products, flattens the nested JSON structure, creates a SQLite database table named products, and inserts all records into /home/interview/inventory.db.

The table should contain the following columns: id, name, category, price, stock_quantity, supplier_name.

Example

API response structure (nested):

{
  "page": 1,
  "total_pages": 4,
  "next": "http://api.inventory.local/products?page=2",
  "products": [
    {
      "id": 1,
      "name": "Laptop",
      "details": {
        "category": "Electronics",
        "price": 999.99,
        "stock_quantity": 25
      },
      "supplier": {
        "name": "Tech Supply Co",
        "country": "USA"
      }
    }
  ]
}

Expected database record (flattened):

id=1, name="Laptop", category="Electronics", price=999.99, stock_quantity=25, supplier_name="Tech Supply Co"

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →