I am retrieving a JSON response from an API which includes a 'Next' field **if** there is another page of results (page only shows 20 results at a time). I want the loop to continue to follow these 'Next' URLS (adding the values on each page) until the 'Next' key is not in the response.

I've tried a couple different things but either it works and only grabs the first page, or it gives an error like: `JSONDecodeError: Expecting value: line 1 column 1 (char 0)`. 

Here is the code so far, hopefully I've explained what I am trying to achieve.

```
totalOrderCount = 0
totalOrderAmount = 0

response = session.get(url+'/ordertransactions').json()

while 'next' in response:
    nextUrl = response['next']
    for i in response['orders']:
        totalOrderCount = totalOrderCount + 1
        totalOrderAmount = totalOrderAmount + i['amount']
    response = session.get(nextUrl).json() # Grab next page of results and perform the above actions again
else:
    for i in response['orders']:
        totalOrderCount = totalOrderCount + 1
        totalOrderAmount = totalOrderAmount + i['amount']

print(totalOrderCount)
print(totalOrderAmount)

```

Thank you for your help!