Help paginating through Canvas API

I have tried using pre-request scripts and other mechanisms but to no avail. This particular endpoint is created in a way so that a link header is passed back after the first call that contains this literal info:
https://my_base_url/api/v1/accounts/1/users?enrollment_type=student&order=desc&sort=last_login&page=1&per_page=10; rel=“current”,

https://my_base_url/api/v1/accounts/1/users?enrollment_type=student&order=desc&sort=last_login&page=2&per_page=10; rel=“next”,

https://my_base_url/api/v1/accounts/1/users?enrollment_type=student&order=desc&sort=last_login&page=1&per_page=10; rel=“first”,

https://my_base_url/api/v1/accounts/1/users?enrollment_type=student&order=desc&sort=last_login&page=4559&per_page=10; rel=“last”

you can see the relative info about the particular page you’re looking at is returned. how do I extract information from the header, which could always be different and iterate from page 1 through whatever the last page might be? I also want to collate the output into a single JSON that can be saved.

maybe something along the lines of setting the “page” query param to whatever the corresponding page is in the link header when “rel=“next””?