<?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: API not retrieving all networks in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403067#M873</link>
    <description>&lt;P&gt;It is working! Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 23:06:39 GMT</pubDate>
    <dc:creator>rubdeadman</dc:creator>
    <dc:date>2022-02-09T23:06:39Z</dc:date>
    <item>
      <title>API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403054#M860</link>
      <description>&lt;P&gt;Hello all! Hope you are doing well. &lt;/P&gt;&lt;P&gt;I have been trying to retrieve my networking information from Postman, but I only get two networks out of the four when I run the GET. I'm able to access all the networks on the Meraki dashboard, but having no luck with APIs. I have created different API keys, but no luck. Any advice?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 19:09:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403054#M860</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T19:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403055#M861</link>
      <description>&lt;P&gt;Could you precise what API call you using ?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:02:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403055#M861</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T20:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403056#M862</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;GET  {{baseUrl}}&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;/organizations/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I got the organization ID from the Meraki Dashboard, but when I try to add it to the URL I get a 401.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"errors"&lt;/SPAN&gt;&lt;SPAN&gt;: [&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"Invalid API key"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:19:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403056#M862</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T20:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403057#M863</link>
      <description>&lt;P data-unlink="true"&gt;So you are trying to Get &lt;A href="https://api.meraki.com/api/v1/organizations/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.meraki.com/api/v1/organizations/&lt;/A&gt;  which should return you a list of Orgs that you have access. Then you will be able to retrieve the ''id'' ( which is the OrgID ) and try https://api.meraki.com/api/v1&lt;SPAN&gt;/organizations/&lt;/SPAN&gt;&lt;STRONG&gt;{organizationId}&lt;/STRONG&gt;&lt;SPAN&gt;/networks &lt;/SPAN&gt; with the correct ID. &lt;/P&gt;&lt;P data-unlink="true"&gt; &lt;/P&gt;&lt;P data-unlink="true"&gt;My favorite way to test these API calls , is by using Chrome and logging to the desired Org and then typing the API url in the url bar.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:26:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403057#M863</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T20:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403058#M864</link>
      <description>&lt;P&gt;Thanks for the advice. I am unsure how to test API calls from Chrome. Can you please provide a site that gives instructions? &lt;BR /&gt;&lt;BR /&gt;And I have followed the correct steps to get the Organizations back. I noticed that the n# is different for the Organizations I am trying to access. I wonder if that is where the problem is. &lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 20:45:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403058#M864</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T20:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403059#M865</link>
      <description>&lt;P&gt;No, I am not using v0. I am using v1. The GET request works for the networks that are on the same shard, but not the other two that are on different shards. &lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 21:44:42 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403059#M865</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T21:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403060#M866</link>
      <description>&lt;P&gt;All networks from the same Org are on the same shard. Do not mix shards ID and Orgs. &lt;/P&gt;&lt;P&gt;That is why it is recommended to use the mega proxy api.meraki.com instead of the shard. If you really want to use the shard , you have to make sure that it is the right one.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:06:12 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403060#M866</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T22:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403061#M867</link>
      <description>&lt;P&gt;I am using the mega proxy api.meraki.com. &lt;/P&gt;&lt;P&gt;I am only seeing the difference in the shard from the dashboard, so I wasn't sure if that was causing the issue. I have never used the shard in the API call. &lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:09:10 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403061#M867</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T22:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403062#M868</link>
      <description>&lt;P&gt;Then the queries would be simply : &lt;/P&gt;&lt;P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;A href="https://api.meraki.com/api/v1/organizations/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.meraki.com/api/v1/organizations/&lt;/A&gt;   ( with a valid API key )&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://api.meraki.com/api/v1" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.meraki.com/api/v1&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;/organizations/&lt;/SPAN&gt;&lt;STRONG&gt;{organizationId}&lt;/STRONG&gt;&lt;SPAN&gt;/networks ( with a valid Org ID obtained from the previous call ) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Simply &lt;STRONG&gt;log&lt;/STRONG&gt; into &lt;STRONG&gt;any&lt;/STRONG&gt; Org that you have a API key in your browser and paste the urls in the url bar :&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RaphaelL_0-1644444873258.png" style="width: 400px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image.png"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/262575i863ACAB06FAAA298/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This is how I test my calls before scripting.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:15:29 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403062#M868</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T22:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403063#M869</link>
      <description>&lt;P&gt;Wow! That was awesome. Thanks for sharing that. I got the results and the Organization was present. However, when I add the organizationId( or the organizationId/networks) I get a 404 error. &lt;/P&gt;&lt;P&gt;I tested the method with the other networks and only one network returned with 200.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:45:53 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403063#M869</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T22:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403064#M870</link>
      <description>&lt;P&gt;Has the Org API settings been enabled ?  :&lt;/P&gt;&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RaphaelL_0-1644446939015.png" style="width: 400px;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image.png"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/262576i754410436419B34C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:49:10 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403064#M870</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T22:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403065#M871</link>
      <description>&lt;P&gt;Yes, it has. &lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:52:25 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403065#M871</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T22:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403066#M872</link>
      <description>&lt;P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;However, when I add the organizationId( or the organizationId/networks) I get a 404 error. &lt;/P&gt;&lt;P&gt;I tested the method with the other networks and only one network returned with 200.&lt;/P&gt;&lt;P&gt;I'm not sure I'm following you. The call &lt;SPAN&gt;&lt;A href="https://api.meraki.com/api/v1" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.meraki.com/api/v1&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;/organizations/&lt;/SPAN&gt;&lt;STRONG&gt;{organizationId}&lt;/STRONG&gt;&lt;SPAN&gt;/networks    It needs a OrgID not a NetworkID. You should be able to list all the networks from that given Org. If it still fails for the same Org , I would open a ticket.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 22:59:53 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403066#M872</guid>
      <dc:creator>Raphael_L</dc:creator>
      <dc:date>2022-02-09T22:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403067#M873</link>
      <description>&lt;P&gt;It is working! Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 23:06:39 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403067#M873</guid>
      <dc:creator>rubdeadman</dc:creator>
      <dc:date>2022-02-09T23:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: API not retrieving all networks</title>
      <link>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403068#M874</link>
      <description>&lt;P&gt;Please direct me to the correct Group if this is incorrect.&lt;/P&gt;&lt;P&gt;After searching, this thread is the closest I have found to my issue. &lt;BR /&gt;I am using the Automation-scripts-Master Python Script for retrieving an inventory of each of my organizations networks but it has started to miss entire organizations. My API key is valid and I can pull the orgs missed if I use py inventorycvs.py -k &amp;lt;myapikey&amp;gt; -o "name" -f c:\temp\listofitems.csv&lt;BR /&gt;I get a list of the Org/networks/items but it is missing orgs. &lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;import sys, getopt, requests, time, datetime, os, smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from urllib.parse import urlencode
from requests import Session, utils

class NoRebuildAuthSession(Session):
    def rebuild_auth(self, prepared_request, response):
        """Prevent auth header stripping on redirect."""

API_MAX_RETRIES             = 3
API_CONNECT_TIMEOUT         = 60
API_TRANSMIT_TIMEOUT        = 60
API_STATUS_RATE_LIMIT       = 429
API_RETRY_DEFAULT_WAIT      = 3

FLAG_REQUEST_VERBOSE        = True

API_BASE_URL                = "https://api.meraki.com/api/v1"
API_KEY_ENV_VAR_NAME        = "MERAKI_DASHBOARD_API_KEY"

def send_email(smtp_server, port, sender_email, sender_password, recipient_email, subject, body, attachment_path):
    try:
        msg = MIMEMultipart()
        msg['From'] = sender_email
        msg['To'] = recipient_email
        msg['Subject'] = subject

        msg.attach(MIMEText(body, 'plain'))

        if attachment_path:
            with open(attachment_path, "rb") as attachment:
                part = MIMEBase('application', 'octet-stream')
                part.set_payload(attachment.read())
            encoders.encode_base64(part)
            part.add_header(
                "Content-Disposition",
                f"attachment; filename={attachment_path.split('/')[-1]}",
            )
            msg.attach(part)

        server = smtplib.SMTP(smtp_server, port)
        server.starttls()
        server.login(sender_email, sender_password)
        server.send_message(msg)
        server.quit()

        print(f"Email sent successfully to {recipient_email}")
    except Exception as e:
        print(f"Failed to send email: {e}")

def merakiRequest(p_apiKey, p_httpVerb, p_endpoint, p_additionalHeaders=None, p_queryItems=None, 
        p_requestBody=None, p_verbose=False, p_retry=0):
    if p_retry &amp;gt; API_MAX_RETRIES:
        if(p_verbose):
            print("ERROR: Reached max retries")
        return False, None, None, None
        
    bearerString = "Bearer " + str(p_apiKey)
    headers = {"Authorization": bearerString}
    if not p_additionalHeaders is None:
        headers.update(p_additionalHeaders)
        
    query = ""
    if not p_queryItems is None:
        qArrayFix = {}
        for item in p_queryItems:
            if isinstance(p_queryItems[item], list):
                qArrayFix["%s[]" % item] = p_queryItems[item]
            else:
                qArrayFix[item] = p_queryItems[item]
        query = "?" + urlencode(qArrayFix, True)
    url = API_BASE_URL + p_endpoint + query
    
    verb = p_httpVerb.upper()
    
    session = NoRebuildAuthSession()
    
    verbs   = {
        'DELETE'    : { 'function': session.delete, 'hasBody': False },
        'GET'       : { 'function': session.get,    'hasBody': False },
        'POST'      : { 'function': session.post,   'hasBody': True  },
        'PUT'       : { 'function': session.put,    'hasBody': True  }
    }

    try:
        if(p_verbose):
            print(verb, url)
            
        if verb in verbs:
            if verbs[verb]['hasBody'] and not p_requestBody is None:
                r = verbs[verb]['function'](
                    url,
                    headers =   headers,
                    json    =   p_requestBody,
                    timeout =   (API_CONNECT_TIMEOUT, API_TRANSMIT_TIMEOUT)
                )
            else: 
                r = verbs[verb]['function'](
                    url,
                    headers =   headers,
                    timeout =   (API_CONNECT_TIMEOUT, API_TRANSMIT_TIMEOUT)
                )
        else:
            return False, None, None, None
    except:
        return False, None, None, None
    
    if(p_verbose):
        print(r.status_code)
    
    success         = r.status_code in range (200, 299)
    errors          = None
    responseHeaders = None
    responseBody    = None
    
    if r.status_code == API_STATUS_RATE_LIMIT:
        retryInterval = API_RETRY_DEFAULT_WAIT
        if "Retry-After" in r.headers:
            retryInterval = r.headers["Retry-After"]
        if "retry-after" in r.headers:
            retryInterval = r.headers["retry-after"]
        
        if(p_verbose):
            print("INFO: Hit max request rate. Retrying %s after %s seconds" % (p_retry+1, retryInterval))
        time.sleep(int(retryInterval))
        success, errors, responseHeaders, responseBody = merakiRequest(p_apiKey, p_httpVerb, p_endpoint, p_additionalHeaders, 
            p_queryItems, p_requestBody, p_verbose, p_retry+1)
        return success, errors, responseHeaders, responseBody        

    try:
        rjson = r.json()
    except:
        rjson = None
        
    if not rjson is None:
        if "errors" in rjson:
            errors = rjson["errors"]
            if(p_verbose):
                print(errors)
        else:
            responseBody = rjson  

    if "Link" in r.headers:
        parsedLinks = utils.parse_header_links(r.headers["Link"])
        for link in parsedLinks:
            if link["rel"] == "next":
                if(p_verbose):
                    print("Next page:", link["url"])
                splitLink = link["url"].split("/api/v1")
                success, errors, responseHeaders, nextBody = merakiRequest(p_apiKey, p_httpVerb, splitLink[1], 
                    p_additionalHeaders=p_additionalHeaders, 
                    p_requestBody=p_requestBody, 
                    p_verbose=p_verbose)
                if success:
                    if not responseBody is None:
                        responseBody = responseBody + nextBody
                else:
                    responseBody = None
    
    return success, errors, responseHeaders, responseBody

# Other functions here...

def main(argv):    
    arg_apikey = None
    arg_orgname = "/all"
    arg_file = None
    arg_email = None  # New email argument

    try:
        opts, args = getopt.getopt(argv, 'hk:o:f:e:')
    except getopt.GetoptError:
        print(readMe)
        sys.exit()
    
    for opt, arg in opts:
        if opt == '-h':
            print(readMe)
        elif opt == '-k':
            arg_apikey = arg
        elif opt == '-o':
            arg_orgname = arg
        elif opt == '-f':
            arg_file = arg
        elif opt == '-e':
            arg_email = arg

    # Validate API key
    apiKey = getApiKey(arg_apikey)
    if apiKey is None:
        print("Error: API key missing!")
        sys.exit()

    filepath = generateFileName() if arg_file is None else arg_file
    # Generate CSV logic...

    # Send email if email argument provided
    if arg_email:
        smtp_server = "smtp.office365.com"
        port = 587
        sender_email = "dwarren@clearlinktech.com"
        sender_password = "There is no spoon."
        subject = "Meraki Inventory CSV File"
        body = f"Attached is the CSV file for {arg_orgname}."

        send_email(smtp_server, port, sender_email, sender_password, arg_email, subject, body, filepath)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; I am curious if I am missing some recent changes or if my rate limiting is incorrect.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;IronBones &lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 15:24:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/api-not-retrieving-all-networks/m-p/5403068#M874</guid>
      <dc:creator>IronBones</dc:creator>
      <dc:date>2025-01-31T15:24:43Z</dc:date>
    </item>
  </channel>
</rss>

