title: How can I loop through a Jira Rest API call, and save each element into a JSON file?
body: <p>I am making a Jira Rest API call to retrieve a data set which has the following format:</p>
  <pre><code>{
      &quot;expand&quot;: &quot;schema,names&quot;,
      &quot;startAt&quot;: 0,
      &quot;maxResults&quot;: 50,
      &quot;total&quot;: 15693,
      &quot;issues&quot;: [
          {
              &quot;expand&quot;: &quot;operations,versionedRepresentations,editmeta,changelog,renderedFields&quot;,
              &quot;id&quot;: &quot;12345&quot;,
              &quot;self&quot;: &quot;https://url.com&quot;,
              &quot;key&quot;: &quot;random text&quot;,
              &quot;fields&quot;: {
                  &quot;customfield_16570&quot;: null,
                  &quot;customfield_18873&quot;: null,
                  &quot;customfield_18470&quot;: null,
                  &quot;customfield_18471&quot;: null,
                  &quot;customfield_20271&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;fixVersions&quot;: [
                      {
                          &quot;self&quot;: &quot;https://url.com&quot;,
                          &quot;id&quot;: &quot;12345&quot;,
                          &quot;description&quot;: &quot;&quot;,
                          &quot;name&quot;: &quot;random text&quot;,
                          &quot;archived&quot;: false,
                          &quot;released&quot;: false
                      }
                  ],
                  &quot;customfield_18874&quot;: null,
                  &quot;resolution&quot;: null,
                  &quot;customfield_13983&quot;: &quot;random text&quot;,
                  &quot;customfield_18875&quot;: null,
                  &quot;customfield_19277&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_15591&quot;: null,
                  &quot;customfield_19278&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;lastViewed&quot;: null,
                  &quot;customfield_17370&quot;: null,
                  &quot;customfield_15594&quot;: null,
                  &quot;customfield_19273&quot;: null,
                  &quot;customfield_19274&quot;: null,
                  &quot;customfield_17771&quot;: null,
                  &quot;customfield_19275&quot;: null,
                  &quot;customfield_18187&quot;: null,
                  &quot;customfield_19276&quot;: null,
                  &quot;priority&quot;: null,
                  &quot;labels&quot;: [
                      &quot;random text&quot;
                  ],
                  &quot;timeestimate&quot;: null,
                  &quot;aggregatetimeoriginalestimate&quot;: 0,
                  &quot;customfield_19270&quot;: &quot;random text&quot;,
                  &quot;issuelinks&quot;: [],
                  &quot;customfield_19271&quot;: null,
                  &quot;customfield_19272&quot;: null,
                  &quot;customfield_18183&quot;: null,
                  &quot;assignee&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;name&quot;: &quot;random text&quot;,
                      &quot;key&quot;: &quot;random text&quot;,
                      &quot;emailAddress&quot;: &quot;random text&quot;,
                      &quot;avatarUrls&quot;: {
                          &quot;48x48&quot;: &quot;https://url.com&quot;,
                          &quot;24x24&quot;: &quot;https://url.com&quot;,
                          &quot;16x16&quot;: &quot;https://url.com&quot;,
                          &quot;32x32&quot;: &quot;https://url.com&quot;
                      },
                      &quot;displayName&quot;: &quot;random text&quot;,
                      &quot;active&quot;: true,
                      &quot;timeZone&quot;: &quot;random text&quot;
                  },
                  &quot;status&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;description&quot;: &quot;random text&quot;,
                      &quot;iconUrl&quot;: &quot;https://url.com&quot;,
                      &quot;name&quot;: &quot;Open&quot;,
                      &quot;id&quot;: &quot;1&quot;,
                      &quot;statusCategory&quot;: {
                          &quot;self&quot;: &quot;https://url.com&quot;,
                          &quot;id&quot;: 2,
                          &quot;key&quot;: &quot;new&quot;,
                          &quot;colorName&quot;: &quot;random text&quot;,
                          &quot;name&quot;: &quot;random text&quot;
                      }
                  },
                  &quot;customfield_18970&quot;: null,
                  &quot;components&quot;: [],
                  &quot;customfield_12071&quot;: &quot;random text&quot;,
                  &quot;customfield_12070&quot;: null,
                  &quot;customfield_15583&quot;: null,
                  &quot;customfield_16672&quot;: null,
                  &quot;customfield_18570&quot;: null,
                  &quot;customfield_14371&quot;: null,
                  &quot;customfield_16671&quot;: null,
                  &quot;customfield_20370&quot;: &quot;&quot;,
                  &quot;customfield_16670&quot;: null,
                  &quot;customfield_14771&quot;: null,
                  &quot;customfield_10970&quot;: &quot;12345&quot;,
                  &quot;aggregatetimeestimate&quot;: null,
                  &quot;customfield_17076&quot;: null,
                  &quot;customfield_17075&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;No&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_17470&quot;: null,
                  &quot;creator&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;name&quot;: &quot;random text&quot;,
                      &quot;key&quot;: &quot;random text&quot;,
                      &quot;emailAddress&quot;: &quot;random text&quot;,
                      &quot;avatarUrls&quot;: {
                          &quot;48x48&quot;: &quot;https://url.com&quot;,
                          &quot;24x24&quot;: &quot;https://url.com&quot;,
                          &quot;16x16&quot;: &quot;https://url.com&quot;,
                          &quot;32x32&quot;: &quot;https://url.com&quot;
                      },
                      &quot;displayName&quot;: &quot;random text&quot;,
                      &quot;active&quot;: true,
                      &quot;timeZone&quot;: &quot;random text&quot;
                  },
                  &quot;subtasks&quot;: [],
                  &quot;customfield_17077&quot;: null,
                  &quot;reporter&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;name&quot;: &quot;vavoicu@contractor.ea.com&quot;,
                      &quot;key&quot;: &quot;vavoicu@contractor.ea.com&quot;,
                      &quot;emailAddress&quot;: &quot;vavoicu@contractor.ea.com&quot;,
                      &quot;avatarUrls&quot;: {
                          &quot;48x48&quot;: &quot;https://url.com&quot;,
                          &quot;24x24&quot;: &quot;https://url.com&quot;,
                          &quot;16x16&quot;: &quot;https://url.com&quot;,
                          &quot;32x32&quot;: &quot;https://url.com&quot;
                      },
                      &quot;displayName&quot;: &quot;random text&quot;,
                      &quot;active&quot;: true,
                      &quot;timeZone&quot;: &quot;random text&quot;
                  },
                  &quot;customfield_14001&quot;: null,
                  &quot;aggregateprogress&quot;: {
                      &quot;progress&quot;: 0,
                      &quot;total&quot;: 0
                  },
                  &quot;customfield_10562&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_12976&quot;: null,
                  &quot;customfield_15604&quot;: null,
                  &quot;progress&quot;: {
                      &quot;progress&quot;: 0,
                      &quot;total&quot;: 0
                  },
                  &quot;customfield_19370&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;,
                      &quot;child&quot;: {
                          &quot;self&quot;: &quot;https://url.com&quot;,
                          &quot;value&quot;: &quot;random text&quot;,
                          &quot;id&quot;: &quot;12345&quot;
                      }
                  },
                  &quot;votes&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;votes&quot;: 0,
                      &quot;hasVoted&quot;: false
                  },
                  &quot;customfield_16372&quot;: null,
                  &quot;issuetype&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;id&quot;: &quot;1&quot;,
                      &quot;description&quot;: &quot;random text&quot;,
                      &quot;iconUrl&quot;: &quot;https://url.com&quot;,
                      &quot;name&quot;: &quot;random text&quot;,
                      &quot;subtask&quot;: false,
                      &quot;avatarId&quot;: 12345
                  },
                  &quot;customfield_16371&quot;: null,
                  &quot;customfield_18674&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_16772&quot;: null,
                  &quot;customfield_16771&quot;: null,
                  &quot;timespent&quot;: null,
                  &quot;customfield_16373&quot;: null,
                  &quot;customfield_20470&quot;: null,
                  &quot;project&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;id&quot;: &quot;12345&quot;,
                      &quot;key&quot;: &quot;random text&quot;,
                      &quot;name&quot;: &quot;random text&quot;,
                      &quot;projectTypeKey&quot;: &quot;software&quot;,
                      &quot;avatarUrls&quot;: {
                          &quot;48x48&quot;: &quot;https://url.com&quot;,
                          &quot;24x24&quot;: &quot;https://url.com&quot;,
                          &quot;16x16&quot;: &quot;https://url.com&quot;,
                          &quot;32x32&quot;: &quot;https://url.com&quot;
                      },
                      &quot;projectCategory&quot;: {
                          &quot;self&quot;: &quot;https://url.com&quot;,
                          &quot;id&quot;: &quot;12345&quot;,
                          &quot;description&quot;: &quot;&quot;,
                          &quot;name&quot;: &quot;random text&quot;
                      }
                  },
                  &quot;aggregatetimespent&quot;: null,
                  &quot;customfield_14108&quot;: [
                      {
                          &quot;self&quot;: &quot;https://url.com&quot;,
                          &quot;value&quot;: &quot;random text&quot;,
                          &quot;id&quot;: &quot;12345&quot;
                      }
                  ],
                  &quot;resolutiondate&quot;: null,
                  &quot;workratio&quot;: 0,
                  &quot;customfield_19871&quot;: null,
                  &quot;watches&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;watchCount&quot;: 0,
                      &quot;isWatching&quot;: false
                  },
                  &quot;customfield_17172&quot;: null,
                  &quot;customfield_17970&quot;: null,
                  &quot;created&quot;: &quot;2021-03-04T06:51:01.000-0800&quot;,
                  &quot;customfield_17176&quot;: null,
                  &quot;customfield_19870&quot;: null,
                  &quot;customfield_17972&quot;: null,
                  &quot;customfield_15953&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_17170&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;random text&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;updated&quot;: &quot;2021-03-04T14:49:24.000-0800&quot;,
                  &quot;customfield_16471&quot;: null,
                  &quot;customfield_16470&quot;: null,
                  &quot;customfield_18371&quot;: null,
                  &quot;customfield_18372&quot;: null,
                  &quot;customfield_14570&quot;: &quot;1|i0jlfo:&quot;,
                  &quot;timeoriginalestimate&quot;: 0,
                  &quot;description&quot;: &quot;random text&quot;,
                  &quot;customfield_13000&quot;: null,
                  &quot;customfield_16872&quot;: null,
                  &quot;customfield_10643&quot;: null,
                  &quot;customfield_10644&quot;: null,
                  &quot;customfield_10888&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;value&quot;: &quot;C - Low&quot;,
                      &quot;id&quot;: &quot;12345&quot;
                  },
                  &quot;customfield_18370&quot;: null,
                  &quot;summary&quot;: &quot;Random text&quot;,
                  &quot;customfield_17670&quot;: null,
                  &quot;customfield_18881&quot;: null,
                  &quot;customfield_15371&quot;: [
                      {
                          &quot;self&quot;: &quot;url.com&quot;,
                          &quot;value&quot;: &quot;Demo&quot;,
                          &quot;id&quot;: &quot;12345&quot;
                      }
                  ],
                  &quot;customfield_18882&quot;: null,
                  &quot;customfield_18883&quot;: null,
                  &quot;customfield_19570&quot;: {
                      &quot;self&quot;: &quot;https://url.com&quot;,
                      &quot;id&quot;: &quot;12345&quot;,
                      &quot;description&quot;: &quot;&quot;,
                      &quot;name&quot;: &quot;Demo&quot;,
                      &quot;archived&quot;: false,
                      &quot;released&quot;: false
                  },
                  &quot;customfield_15372&quot;: null,
                  &quot;customfield_11572&quot;: null,
                  &quot;customfield_13997&quot;: &quot;item NR&quot;,
                  &quot;customfield_18886&quot;: null,
                  &quot;environment&quot;: null,
                  &quot;duedate&quot;: null,
                  &quot;customfield_17270&quot;: null
              }
          }    
      ]
  }
  </code></pre>
  <p>At first I've tried using a <code>requests.get()</code> syntax in order to get the full list of items but the problem was that my call retrieved only <strong>50</strong> results instead of <strong>15693</strong> as stated in <strong>&quot;total&quot;</strong> field. So... I am struggling to figure out how can I loop through all those 15693 results and write them into a new JSON file using Python. Below is the code used:</p>
  <pre><code>import requests
  import json
  import logging
  import stdiomask
  import argparse
  
  logging.captureWarnings(True) # 
  
  
  # ap = argparse.ArgumentParser()
  # ap.add_argument(&quot;-n&quot;, &quot;--name&quot;, required=True, help=&quot;Jira user&quot;)
  # ap.add_argument(&quot;-p&quot;, &quot;--pass&quot;, required=True, help=&quot;Jira password&quot;)
  # args=vars(ap.parse_args())
  # userJira = args[&quot;name&quot;]
  # passJira = args[&quot;pass&quot;]
  
  
  serverURL = 'https://jiraurl.com'
  user = input(&quot;Jira user: &quot;)
  password = stdiomask.getpass(prompt='Jira Password: ', mask='*')
  # user = userJira
  # password = passJira
  jql = '/rest/api/2/search?jql=project = Demo AND issuetype = BUG ORDER BY createdDate DESC'
  
  response = requests.get(serverURL + jql,verify=False,auth=(user, password))
  
  #=================================================================================================
  #==== | Save json results | ====
  #=================================================================================================
  with open('test.json', 'w', encoding='utf-8') as f:
      json.dump(response.json(), f, ensure_ascii=False, indent=4)
  #=================================================================================================
  </code></pre>
  <p>So this code gets the job done but only for the first 50 items</p>
  <p>Then after reading other posts related to this topic I've tried this:</p>
  <pre><code>import json
  import stdiomask
  import requests
  
  from jira import JIRA
  
  user = input(&quot;Jira user: &quot;)
  password = stdiomask.getpass(prompt='Jira Password: ', mask='*')
  options = {'server': 'https://url.com'}
  jira = JIRA(options, basic_auth=(user, password))
  size = 200
  initial = 0
  while True:
      start= initial*size
      issues = jira.search_issues('project = Demo AND issuetype = BUG ORDER BY createdDate DESC',  start,size)
      if len(issues) == 0:
          break
      initial += 1
      for issue in issues:
          print(issue)
  </code></pre>
  <p>With this code I am able to loop through all of the items and print their names in the console, but I need to get the complete data set in json format for each item (not just the ticket name) and save it into a JSON file.</p>