title: While loop to make API calls until a condition is met
body: <p>I want to make API calls until a condition is met. I figured I might use a while loop.</p>
  
  <p>I have a JSON response from the server that is paginated. </p>
  
  <pre><code>{
      "services": [
          {
              "id": "ABC12",
              "name": "Networks",
              "description": null,
              "status": "active",
              "teams": [
                  {
                      "id": "XYZ12",
                      "type": "team_reference",
                      "summary": "Network Systems ",
                  }
              ],
              "acknowledgement_timeout": null,
              "auto_resolve_timeout": null,
              "alert_grouping": "intelligent",
              "alert_grouping_timeout": null,
              "integrations": [],
              "response_play": null,
              "type": "service",
              "summary": "All Events",
          }
       ],
       "limit": 25,
       "offset": 0,
       "total": null,
       "more": true
  }
  </code></pre>
  
  <p><code>limit - max I can set is 100.</code></p>
  
  <p><code>offset - If specified, shows results from that point.</code></p>
  
  <p><code>more - If TRUE, there are more results. If FALSE, that is the end.</code></p>
  
  <p>for more info on this pagination - <a href="https://v2.developer.pagerduty.com/docs/pagination" rel="nofollow noreferrer">https://v2.developer.pagerduty.com/docs/pagination</a></p>
  
  <p>I need to match the <code>name</code> "Networks" and get its corresponding <code>id</code> "ABC12". The problem is, I have to paginate make multiple calls to the API. </p>
  
  <p>I have written this so far.</p>
  
  <pre><code>import requests
  import json
  import urllib3
  
  # Supress SSL warnings
  urllib3.disable_warnings()
  
  # API key
  API_KEY = '12345asdfg'
  
  def list_services():
  
      x = 25
      y = 0
      results = []
  
      url = f'https://api.pagerduty.com/services/?limit={x}&amp;offset={y}'
      headers = {
          'Accept': 'application/vnd.pagerduty+json;version=2',
          'Authorization': 'Token token={token}'.format(token=API_KEY)
      }
      current_page = json.loads(requests.get(url, verify=False, headers=headers).content.decode('UTF-8'))
      results.append(current_page)
  
      while current_page['more'] == 'True':
          y = y + 1
          current_page = json.loads(requests.get(url, verify=False, headers=headers).content.decode('UTF-8'))
          results.append(current_page)
          print(results) # Does not print anything
      print(results) # Prints only the first call results, the while loop 
                     # doesn't seem to work.
  
  if __name__ == '__main__':
      list_services()
  </code></pre>
  
  <p>the <code>print(results)</code> outside the while loop prints only the first API call results. The while loop doesn't seem to work. But the code compiles without any errors.</p>
  
  <ol>
  <li>how do I set the value of <code>x</code> to <code>25</code> and make API calls and append the results to <code>results</code> until <code>more</code> is false? </li>
  </ol>
  
  <p>OR </p>
  
  <ol start="2">
  <li>how do I make multiple API calls until I find the match. If I found a match, then stop making the call. </li>
  </ol>
  
  <p>Or is there a better cleaner way to do this?</p>