Write a Python script to paginate through a REST API, extract JSON payloads, and transform them into a flattened relational format.