<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python pagination get  8000 devices in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444658#M6968</link>
    <description>&lt;P&gt;Solved it!&lt;/P&gt;&lt;P&gt;i can now get 8000 devices in a single organization using the following Function:&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;def getNetworksDevices(p_orgid):
    results = []
    try: 
        r = requests.get('https://api.meraki.com/api/v1/organizations/%s/devices' % (p_orgid),headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
        if r.status_code == 200:
            raw = r.json()
            for i in raw:  
                results.append(i)

            while 'next' in r.links :
                r = requests.get(r.links['next']['url'],headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
                #print(r.links)
                raw = r.json()
                for i in raw:  
                    results.append(i)
            #print (len(results))
        return (results)    
    except:
        print('ERROR 02: Unable to contact Meraki cloud')
        print ('API response: {}'.format(r.status_code))&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Oct 2020 14:40:26 GMT</pubDate>
    <dc:creator>johanoosterwaal</dc:creator>
    <dc:date>2020-10-28T14:40:26Z</dc:date>
    <item>
      <title>Python pagination get  8000 devices</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444657#M6967</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm trying to get all devices in an organization via a Python script and know there is a limit of 1000 devices per page. &lt;/P&gt;&lt;P&gt;The problem is i have 8000 devices so i need to use header links to grabs the next pages. &lt;/P&gt;&lt;P&gt;Being banging my head against the wall for an hour now but cannot seem the figure out how to implement pagination using the following function&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;def getNetworksDevices(p_orgid):
    try: 
        r = requests.get('https://api.meraki.com/api/v1/organizations/%s/devices' % (p_orgid),headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
        while r.status_code == 429:
            time.sleep(int(r.headers['Retry-After']))
            r = requests.get('https://api.meraki.com/api/v1/organizations/%s/devices' % (p_orgid),headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
            if r.status_code == 200:
                return(r.json())
        if r.status_code == 200:
            return (r.json())
    except:
        print('ERROR 02: Unable to contact Meraki cloud')
        print ('API response: {}'.format(r.status_code))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Oct 2020 19:01:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444657#M6967</guid>
      <dc:creator>johanoosterwaal</dc:creator>
      <dc:date>2020-10-27T19:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python pagination get  8000 devices</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444658#M6968</link>
      <description>&lt;P&gt;Solved it!&lt;/P&gt;&lt;P&gt;i can now get 8000 devices in a single organization using the following Function:&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;def getNetworksDevices(p_orgid):
    results = []
    try: 
        r = requests.get('https://api.meraki.com/api/v1/organizations/%s/devices' % (p_orgid),headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
        if r.status_code == 200:
            raw = r.json()
            for i in raw:  
                results.append(i)

            while 'next' in r.links :
                r = requests.get(r.links['next']['url'],headers={'X-Cisco-Meraki-API-Key': ARG_APIKEY,'Content-Type': 'application/json'} )
                #print(r.links)
                raw = r.json()
                for i in raw:  
                    results.append(i)
            #print (len(results))
        return (results)    
    except:
        print('ERROR 02: Unable to contact Meraki cloud')
        print ('API response: {}'.format(r.status_code))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Oct 2020 14:40:26 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444658#M6968</guid>
      <dc:creator>johanoosterwaal</dc:creator>
      <dc:date>2020-10-28T14:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python pagination get  8000 devices</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444659#M6969</link>
      <description>&lt;P data-unlink="true"&gt;you should take a look at the &lt;A href="https://pypi.org/project/meraki/" target="_self" rel="nofollow noopener noreferrer"&gt;meraki python library&lt;/A&gt;.&lt;/P&gt;&lt;P data-unlink="true"&gt;It is easier to use than using standard requests and it will take care about all throttling limits, pagination, ....&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 15:24:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444659#M6969</guid>
      <dc:creator>Greenberet</dc:creator>
      <dc:date>2020-10-28T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python pagination get  8000 devices</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444660#M6970</link>
      <description>&lt;P&gt;i will thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 17:06:23 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444660#M6970</guid>
      <dc:creator>johanoosterwaal</dc:creator>
      <dc:date>2020-10-28T17:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python pagination get  8000 devices</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444661#M6971</link>
      <description>&lt;P&gt;Thanks for sharing !!!&lt;/P&gt;&lt;P&gt;I tested in my environment and it works !!!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 16:39:27 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-pagination-get-8000-devices/m-p/5444661#M6971</guid>
      <dc:creator>klaustecnico</dc:creator>
      <dc:date>2021-08-30T16:39:27Z</dc:date>
    </item>
  </channel>
</rss>

