Get list of all mobile Phones and their Numbers across all networks

JimK
Comes here often

Get list of all mobile Phones and their Numbers across all networks

Hi, we have a bunch of "Networks" consisting of iOS devices and a few Android phones, is there a way to list all the phones (iPhones & Android Phones) and the associated Phone numbers, SN, IMEI numbers? I can get a list per Network but I would like to get one big one from all the networks.

 

And/Or is there a way to search by phone number across all networks. I can search per network but can't seem to do it across them all.

 

We are trying to locate a few phones we only have phone numbers for and going into each customers network to see if it is in there is very time consuming.

3 Replies 3
alemabrahao
Kind of a big deal
Kind of a big deal

Have you checked this API?

 

https://developer.cisco.com/meraki/api-latest/#!get-network-sm-devices

I am not a Cisco Meraki employee. My suggestions are based on documentation of Meraki best practices and day-to-day experience.

Please, if this post was useful, leave your kudos and mark it as solved.
PaulF
Meraki Employee
Meraki Employee

as per the API above:

 

# This script, for a given API key, and org ID
# For each network, get the SM devices and print to screen
# Mandatory arguments:
# -k <API KEY>      : Your Meraki Dashboard API Key
# -o <Org. ID>      : Your Meraki Org ID
# Pre requisites:
# Meraki library : pip install meraki : https://developer.cisco.com/meraki/api/#/python/getting-started

import meraki
import sys, getopt


def main(argv):

    print("Meraki Library version: ")
    print(meraki.__version__)

    arg_apikey = False

    try:
        opts, args = getopt.getopt(argv, 'k:o:')
    except getopt.GetOptError:
        printhelp(argv)
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-k':
            arg_apikey = arg
        if opt == "-o":
            arg_orgId = arg

    # Create Meraki Client Object and initialise
    client = meraki.DashboardAPI(api_key=arg_apikey)

    networks = client.organizations.getOrganizationNetworks(organizationId=arg_orgId)

    print("networkID, model, osName, systemModel")
    for network in networks:
        networkName = (network['name'])
        networkID = (network['id'])

        try:
            devices = client.sm.getNetworkSmDevices(networkId=networkID, fields={"ip"})
            if len(devices) == 0:
                # no devices
                print("No devices in this SM network")
            else:
                for device in devices:
                    print(networkID, ",", device["name"], ",", device["osName"], ",", device["phoneNumber"])

        except meraki.APIError as e:
            print("No SM in " + networkName + " network")


def printhelp():
    # prints help information
    print('This is a script to Get the SM devices and their phone number across multiple networks.')
    print('')
    print('Mandatory arguments:')
    print(' -k <api key>         : Your Meraki Dashboard API key')
    print(' -o <Org. ID>         : Your Meraki Org ID')


if __name__ == '__main__':
    main(sys.argv[1:])

 

you'll need to install the Meraki Library

 

and it's launched with:

 

python3 yourscriptname.py -k YOURAPIKEY -o YOURORGID

JimK
Comes here often

Thanks for the help guys, I did see the API but wasn't very familiar with how to use it. Sorry for the delay in getting back I got pulled in other directions. 

 

I was able to set up everything PaulF posted and then eventually I was able to figure out how to get the orgid however I am stuck as I am getting the message

 

"No devices in this SM network"

 

but we have 

 

* 414 devices (mostly iOS iPhones and also a few iPads, iPods and a few Android phones)
* across 82 networks

* No other devices besides iOS/Android

 

So I must be doing something wrong but don't know what.

 

Here is the output from the code I used to get the orgID

 

 

2023-04-11 15:10:36       meraki:     INFO > Meraki dashboard API session initialized with these parameters: {
'version': '1.32.1', 
'api_key': '**last 4 of my api key was in here**', 
'base_url': 'https://api.meraki.com/api/v1', 
'single_request_timeout': 60', 
'certificate_path': '', 
'requests_proxy': '', 
'wait_on_rate_limit': True, 
'nginx_429_retry_wait_time': 60, 
'action_batch_retry_wait_time': 60, 
'retry_4xx_error': False', 
'retry_4xx_error_wait_time': 60', 
'maximum_retries': 2', 
'simulate': False', 
'be_geo_id': None', 
'caller': None', 
'use_iterator_for_get_pages': False}

2023-04-11 15:10:36       meraki:     INFO > GET https://api.meraki.com/api/v1/organizations

2023-04-11 15:10:37       meraki:     INFO > organizations, getOrganizations - 200 OK
[{
'id': 'a 6 digit number was in here', 
'name': 'Our company name was in here', 
'url': 'https://n22.meraki.com/o/{{6 digits numbers/letters not sure if it safe to post}}/manage/organization/overview', 
'api': {'enabled': True}', 
'licensing': {'model': 'co-term'}', 
'cloud': {'region': {'name': 'North America'}}', 
'management': {'details': []}
}]

 

 

Here is the code I used to get the orgID

 

 

API_KEY = '**Used my api key**'
dashboard = meraki.DashboardAPI(API_KEY)
response = dashboard.organizations.getOrganizations()

 

 

Which I got from here: Getting-started-with-Meraki-API-using-Python-Part-2-Python-Setup 

 

Here is the output from the yourscriptname.py from the above post:

 

2023-04-11 15:11:56       meraki:     INFO > Meraki dashboard API session initialized with these parameters: {'version': '1.32.1', 
'api_key': '**last 4 of my api key was in here**',   
'base_url': 'https://api.meraki.com/api/v1', 
'single_request_timeout': 60', 
'certificate_path': '', 
'requests_proxy': '', 
'wait_on_rate_limit': True', 
'nginx_429_retry_wait_time': 60', 
'action_batch_retry_wait_time': 60', 
'retry_4xx_error': False', 
'retry_4xx_error_wait_time': 60', 
'maximum_retries': 2', 
'simulate': False', 
'be_geo_id': None', 
'caller': None', 
'use_iterator_for_get_pages': False}

2023-04-11 15:11:56       meraki:     INFO > GET https://api.meraki.com/api/v1/organizations/{{The 6 digit 'id' number from the first script was here}}/networks

2023-04-11 15:11:56       meraki:     INFO > organizations, getOrganizationNetworks; page 1 - 200 OK
networkID, model, osName, systemModel

2023-04-11 15:11:56       meraki:     INFO > GET https://api.meraki.com/api/v1/networks/L_{{18 numbers}}/sm/devices

2023-04-11 15:11:57       meraki:     INFO > sm, getNetworkSmDevices; page 1 - 200 OK
No devices in this SM network

2023-04-11 15:11:57       meraki:     INFO > GET https://api.meraki.com/api/v1/networks/L_{{18 numbers}}/sm/devices

2023-04-11 15:11:59       meraki:     INFO > sm, getNetworkSmDevices; page 1 - 200 OK

Traceback (most recent call last):
  File "D:\Dev\Misc\Meraki API\iOS\iOS.py", line 71, in <module>
    main(sys.argv[1:])
  File "D:\Dev\Misc\Meraki API\iOS\iOS.py", line 55, in main
    print(networkID, ",", device["name"], ",", device["osName"], ",", device["phoneNumber"])
KeyError: 'phoneNumber'

 

Any ideas as to what I can do to fix whatever I am doing wrong?

 

 

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.
Labels