<?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: Referencing a client's lastSeen time in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398580#M214</link>
    <description>&lt;P&gt;That was the very first thing I installed, using that exact page as a guide.&lt;/P&gt;&lt;P&gt;I get that my questions are super basic and I'm sorry for that, but I really do go through the Meraki API documentation - and have been for a few weeks now. I've come along way, especially for never having done anything like this ever. If reinstalling everything is actually going to help, then I will gladly do that. But I'm a little hesitant, because I'm so close to finishing the one thing I need this for and I'm concerned that this will just be taking two steps back.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Sep 2021 20:01:31 GMT</pubDate>
    <dc:creator>lonestar2</dc:creator>
    <dc:date>2021-09-03T20:01:31Z</dc:date>
    <item>
      <title>Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398573#M207</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;I'm familiar with Meraki but this is my first rodeo for API/Python things, so I imagine the problem is my missing something super simple. I have one script that depends on the last seen time of some wireless clients, and I'm having a difficult time pulling that value. So I made the below script just to print the 'lastSeen' time and I'll adapt it later into the larger script.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Depending on the syntax in the lastSeen lookup below, I either get "KeyError: 'lastSeen'" or "NameError: name 'lastSeen' is not defined".&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I know the issue is probably my not being clear enough that I'm trying to pull the last seen time, but I don't know what I'm supposed to write instead. Specifically what am I missing?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;#!/usr/bin/python
 
import meraki
import json
 
#
# Python Script Using Meraki API to find last seen time of client device
# Prints out the time last seen
#
 
# Enter Organization ID Here, to be converted into an environment variable later
apikey = 'abcdeabcdeabcdeabcdeabcdeabcdeabcde'
 
# Enter Organization ID Here
organizationid = '54321'
 
# Enter Client MAC Address
mac = 'ab:cd:ef:01:23:45'
 
#Network lookup
networks = meraki.getnetworklist(apikey, organizationid, suppressprint=True)
 
#Loop through Network
for row in networks:
 
        #Device Lookup
        devices = meraki.getnetworkdevices(apikey, row['id'], suppressprint=True)
 
        #Loop through each device in network
        for device in devices:
 
            #Client Lookup
            clients = meraki.getclients(apikey, device['serial'], suppressprint=True)
            #print(format(str(device['serial'] + '\n')) + (str(device['mac'])))
            
            #Loop to find client
            for client in clients:
 
                #LastSeen lookup***This is the main line that is giving me trouble
                lastOnline = client['lastSeen']
 
                #print(format(str(client['mac'] + '\n')))
                print(format('Last Seen: ') + str(['lastSeen'] + '\n'))
                break
            else:
                continue
            break
        else:
            continue
        break
 
    #Print Statement for not found in loop
else:
    print ('Made it to the end of the script')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 16:45:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398573#M207</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T16:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398574#M208</link>
      <description>&lt;P&gt;Based on the names of these methods, it looks like you're using an old version of the SDK.&lt;/P&gt;&lt;P&gt;The current Python library is fetchable via `pip install --update meraki`&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:17:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398574#M208</guid>
      <dc:creator>John-on-API</dc:creator>
      <dc:date>2021-09-03T19:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398575#M209</link>
      <description>&lt;P&gt;Hmmm that's strange, I only installed the packages not three weeks ago. I will check again.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:20:26 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398575#M209</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T19:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398576#M210</link>
      <description>&lt;P&gt;It went from 1.10.0 to 1.12.0, so I guess that's something! Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:24:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398576#M210</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T19:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398577#M211</link>
      <description>&lt;P&gt;This syntax looks like something from a very old version of the SDK, or from API v0 instead of v1.&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;networks = meraki.getnetworklist(apikey, organizationid, suppressprint=True)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What package exactly is 'import meraki' importing? It seems to me it's not the official SDK.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developer.cisco.com/meraki/api-v1/#!get-organization-networks" target="_blank" rel="nofollow noopener noreferrer"&gt;From the docs: https://developer.cisco.com/meraki/api-v1/#!get-organization-networks&lt;/A&gt;&lt;/P&gt;&lt;P&gt;we can find an example of what using the current SDK looks like:&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;dashboard = meraki.DashboardAPI(API_KEY)

organization_id = '549236'

response = dashboard.organizations.getOrganizationNetworks(
    organization_id, total_pages='all'
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:38:53 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398577#M211</guid>
      <dc:creator>John-on-API</dc:creator>
      <dc:date>2021-09-03T19:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398578#M212</link>
      <description>&lt;P&gt;To my knowledge I'm running the most recent versions of all the Meraki packages. The code I posted is adapted from scripts I found online &lt;A href="https://github.com/steinbep/Meraki-API---Python" target="_self" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt;. My first script that checks if the MAC is on the network runs perfectly. My main issue is calling up the 'lastSeen' element, which really seems to be a syntax error, which is what I'm looking for help on.&lt;/P&gt;&lt;P&gt;Also, 'import meraki' is importing meraki.py from the scripts I linked above.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:49:04 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398578#M212</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T19:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398579#M213</link>
      <description>&lt;P&gt;&lt;A title="This is the Python SDK" href="https://pypi.org/project/meraki/" target="_blank" rel="noopener nofollow noreferrer"&gt;This is the Python SDK&lt;/A&gt; you want. What you're referencing doesn't look familiar and may be part of the problem.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pypi.org/project/meraki/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://pypi.org/project/meraki/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 19:52:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398579#M213</guid>
      <dc:creator>John-on-API</dc:creator>
      <dc:date>2021-09-03T19:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398580#M214</link>
      <description>&lt;P&gt;That was the very first thing I installed, using that exact page as a guide.&lt;/P&gt;&lt;P&gt;I get that my questions are super basic and I'm sorry for that, but I really do go through the Meraki API documentation - and have been for a few weeks now. I've come along way, especially for never having done anything like this ever. If reinstalling everything is actually going to help, then I will gladly do that. But I'm a little hesitant, because I'm so close to finishing the one thing I need this for and I'm concerned that this will just be taking two steps back.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 20:01:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398580#M214</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T20:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398581#M215</link>
      <description>&lt;P&gt;Nothing wrong with basic questions!&lt;/P&gt;&lt;P&gt;Pulling the lastSeen time is trivial with the official SDK.&lt;/P&gt;&lt;PRE class="lia-code-sample language-python"&gt;&lt;CODE&gt;import meraki

dashboard = meraki.DashboardAPI(suppress_logging=True)

clients = dashboard.networks.getNetworkClients(
    "network_id_here"
)

for client in clients:
    print(f'lastSeen: {client["lastSeen"]}')

print('done')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 20:10:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398581#M215</guid>
      <dc:creator>John-on-API</dc:creator>
      <dc:date>2021-09-03T20:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing a client's lastSeen time</title>
      <link>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398582#M216</link>
      <description>&lt;P&gt;Thanks! That's it.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 20:14:21 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/referencing-a-client-s-lastseen-time/m-p/5398582#M216</guid>
      <dc:creator>lonestar2</dc:creator>
      <dc:date>2021-09-03T20:14:21Z</dc:date>
    </item>
  </channel>
</rss>

