# Help with sample Python code

**URL:** <https://devforum.zoom.us/t/help-with-sample-python-code/15262>\
**Category:** API and Webhooks\
**Created:** [April 28, 2020, 5:35pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262 "2020-04-28T17:35:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrodrigues](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rrodrigues/32/5560_2.png) [@rrodrigues](https://devforum.zoom.us/u/rrodrigues)\
**Post date:** [April 28, 2020, 5:35pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/1 "2020-04-28T17:35:03Z")

</div>

Hi Everyone,

I’m experiencing a bit of trouble, and wondering if someone could shed light on what I’m doing wrong.

I want to list all our user accounts individually, on a separate line, like this:

> Found User Account: [bobjackson@company.org](mailto:bobjackson@company.org)  
> Found User Account: [janedoe@company.org](mailto:janedoe@company.org)  
> Found User Account: [johnsmith@company.org](mailto:johnsmith@company.org)

With the Python Requests library, I managed to page through the JSON results and get all users in an array. Fine. But what I’m having difficulties with is printing out the email of each individual user.

These are the results I’m getting:

> Found User Account: [‘bobjackson@company.org’, ‘janedoe@company.org’, ‘johnsmith@company.org’]  
> Found User Account: [‘kensmith@company.org’,‘loisjackson@company.org’,‘marysmith@company.org’]  
> Found User Account: [‘nancydoe@company.org’,‘oscarmartinez@company.org’,‘paulmorgan@company.org’]

This is the Python code I’m using:

> ```
> import requests
> 
> url_address = "https://api.zoom.us/v2/users"
> headers = {
> "Authorization": "Bearer " + "MY_JWT_TOKEN",
> }
> 
> # find out total number of pages
> r = requests.get(url=url_address, headers=headers).json()
> total_pages = int(r['page_count']) + 1
> 
> # results will be appended to this list
> all_entries = []
> 
> # loop through all pages and return JSON object
> for page in range(1, total_pages):
> 
> url = url_address + "?page_number=" + str(page)
> user_data = requests.get(url=url, headers=headers).json()
> user_ids = [(user['email']) for user in user_data['users']]
> all_entries.append(user_ids)
> page += 1
> 
> data = list(all_entries)
> 
> for email in data:
> print('Found User Account: {}'.format(email))
> 
> ```

Any help would be GREATLY appreciated. Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![klassroom](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@klassroom](https://devforum.zoom.us/u/klassroom)\
**Post date:** [April 28, 2020, 5:57pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/2 "2020-04-28T17:57:19Z")

</div>

Hi @rrodrigues,

Can you attach the API response that you get?

Thanks

---

<div class="post-metadata">

**Author:** ![rrodrigues](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rrodrigues/32/5560_2.png) [@rrodrigues](https://devforum.zoom.us/u/rrodrigues)\
**Post date:** [April 28, 2020, 6:07pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/3 "2020-04-28T18:07:09Z")

</div>

What’s the fastest way to send you that info? Postman?

---

<div class="post-metadata">

**Author:** ![rrodrigues](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rrodrigues/32/5560_2.png) [@rrodrigues](https://devforum.zoom.us/u/rrodrigues)\
**Post date:** [April 29, 2020, 2:23am UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/4 "2020-04-29T02:23:15Z")

</div>

I was able to fix the issue by changing a few lines of code in my **FOR** loop:

1. Changed **all\_entries.append(user\_ids)** to **all\_entries._extend_(user\_ids)**
2. Then I changed **data = list(all\_entries)**, which was useless, to **data = all\_entries** , and placed it above the **page += 1** counter.

New working code below:

> ```
> # loop through all pages and return JSON object
> for page in range(1, total_pages):
> url = url_address + "?page_number=" + str(page)
> user_data = requests.get(url=url, headers=headers).json()
> user_ids = [(user['email']) for user in user_data['users']]
> all_entries.extend(user_ids)
> data = all_entries
> page += 1
>  
> for email in data:
> print('Found User Account: {} '.format(email))
> 
> ```

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [May 4, 2020, 5:56pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/5 "2020-05-04T17:56:04Z")

</div>

Hey @rrodrigues,

Happy to hear you figured out the issue! 🙂

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 9:02pm UTC](https://devforum.zoom.us/t/help-with-sample-python-code/15262/6 "2020-08-21T21:02:03Z")

</div>

Closed on August 21, 2020, 9:02pm UTC


