Problems getting Device Owners from API

Solved
DiegoMesa
New here

Problems getting Device Owners from API

Hello everyone! 
I am working on a project at work and I desperately need to get the full MDM Device List including the "Owner" field. Until now I managed to get all devices, their SN, Model, etc... but no luck getting the Owner field. I've tried everything. Do you know how this can be achieved? I would appreciate your help a lot! 

This is my code so far:

def get_raw_meraki_assets():

    BASE_URL = 'https://api.meraki.com/api/v1'
    endpoint_devices = f"{BASE_URL}/networks/{network_id}/sm/devices"
    response = requests.get(endpoint_devices, headers=headers)
    devices = response.json()
    meraki_df = pd.DataFrame(devices)
    return meraki_df

 

1 Accepted Solution
DiegoMesa
New here

I found a solution !

def get_meraki_devices_with_fields(network_id, api_key):
    url = f"https://api.meraki.com/api/v1/networks/{network_id}/sm/devices"
    headers = {
        "X-Cisco-Meraki-API-Key": api_key,
        "Content-Type": "application/json"
    }

    params = {
        "fields[]": ["ownerEmail", "ip", "lastConnected", "location"] 
    }

    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    
    return response.json()

 
The API documentation wasn't great to be honest, and their "example code" doesn't work. Luckily, chatGPT had the answer for me. 

Thank you for taking time and effort in helping me alemabrahao! 


View solution in original post

6 Replies 6
alemabrahao
Kind of a big deal
Kind of a big deal

Use the endpoint /networks/{network_id}/sm/users to get the owner information and combine the device data with the owner data.

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.
DiegoMesa
New here

Hi alemabrahao!
Thank you a lot for your response! 
I indeed managed to get all users, so this is definitely a good step towards a fix. I have one more question, hope you can help me with this too; how do I associate the users with the devices? The "id" column/field doesn't seem to be shared. Is there any field they both share that I can use to merge the tables? 

alemabrahao
Kind of a big deal
Kind of a big deal

Hi,

 

To associate users with devices, you can try using the deviceId field from the users' data and the id field from the devices' data. These fields should allow you to merge the two datasets.

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.
DiegoMesa
New here

Hi! 
I don't get those fields 😕 
For devices I get this columns: 

Index(['id', 'name', 'tags', 'ssid', 'wifiMac', 'osName', 'systemModel',
       'uuid', 'serialNumber', 'hasChromeMdm'],
      dtype='object')

For users I get these: 

Index(['id', 'email', 'fullName', 'username', 'hasPassword', 'tags',
       'adGroups', 'azureAdGroups', 'samlGroups', 'asmGroups', 'isExternal',
       'sspEnabled', 'displayName', 'hasIdentityCertificate', 'userThumbnail'],
      dtype='object')

 The ids of course don't apply, since they refer to different objects. 
Is there anything I could do to get the desired field?

Thank you again for your help, appreciate it!

alemabrahao
Kind of a big deal
Kind of a big deal

Maybe you can try associating users with devices by using the wifiMac field from the devices data and the email or username field from the users data.

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.
DiegoMesa
New here

I found a solution !

def get_meraki_devices_with_fields(network_id, api_key):
    url = f"https://api.meraki.com/api/v1/networks/{network_id}/sm/devices"
    headers = {
        "X-Cisco-Meraki-API-Key": api_key,
        "Content-Type": "application/json"
    }

    params = {
        "fields[]": ["ownerEmail", "ip", "lastConnected", "location"] 
    }

    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    
    return response.json()

 
The API documentation wasn't great to be honest, and their "example code" doesn't work. Luckily, chatGPT had the answer for me. 

Thank you for taking time and effort in helping me alemabrahao! 


Get notified when there are additional replies to this discussion.