meraki / dashboard-api-python

Official Dashboard API library (SDK) for Python
MIT License
293 stars 154 forks source link

Function "getNetworkClients" doesn't cover all Meraki API query parameters #161

Closed wowkmw closed 3 years ago

wowkmw commented 3 years ago

The latest version of the Python Meraki API function "getNetworkClients" only covers a subset of all available official API's HTTP parameters.

TKIPisalegacycipher commented 3 years ago

This will be solved when the SDK is updated with all the new releases coming out in the official API. A ton of new features are coming hard and fast so stay tuned for an update in August.

wowkmw commented 3 years ago

Thanks, looking forward to it!

Nothing4You commented 3 years ago

as a workaround until this is available I just copied the method into my code with adjusted query_params.

that seems to work fine as well, although i did notice that it does not seem to like passing a list as param value. as a workaround I'm currently passing the key with a [] suffix:

    filter_ = {
        "statuses[]": "Online",
        "recentDeviceConnections[]": "Wireless",
    }

    clients = await getNetworkClients(
        meraki_api.networks,
        network,
        total_pages="all",
        perPage=1000,
        **filter_,
    )

this obviously only works when you only have single item lists.

wowkmw commented 3 years ago

I just took the array processing snippets from another Meraki function and patched the rules.

def _getNetworkClients(self, networkId: str, total_pages=1, direction="next", **kwargs):
        kwargs.update(locals())
        metadata = {
            "tags": ["networks", "monitor", "clients"],
            "operation": "getNetworkClients"
        }
        resource = f"/networks/{networkId}/clients"
        query_params = ["t0", "timespan", "perPage", "startingAfter",
                        "endingBefore", "os", "statuses", "recentDeviceConnections", ]
        params = {k.strip(): v for k, v in kwargs.items()
                  if k.strip() in query_params}
        array_params = ["statuses", "recentDeviceConnections", ]
        for k, v in kwargs.items():
            if k.strip() in array_params:
                params[f"{k.strip()}[]"] = kwargs[f"{k}"]
                params.pop(k.strip())
        return self._session.get_pages(metadata, resource, params, total_pages, direction)

Then I can override the built-in function as such: meraki.Networks.getNetworkClients = _getNetworkClients

TKIPisalegacycipher commented 3 years ago

This is now updated and PyPI package updated.