balena-io / balena-sdk-python

Balena SDK for Python
Apache License 2.0
67 stars 46 forks source link

User wants to be able to filter devices that have specific tags using the python balena-sdk #283

Closed jellyfish-bot closed 1 year ago

jellyfish-bot commented 1 year ago

[thgreasi] undefined

jellyfish-bot commented 1 year ago

[thgreasi] This has attached https://jel.ly.fish/e9b95dc0-817d-40b0-bd82-03411a22ee85

otaviojacobi commented 1 year ago

Hello, after the release of sdk v13 in #326 This can now be achieved with something like:

from balena import Balena

sdk = Balena()
sdk.auth.login(...)

sdk.models.device.getAllByApplication(APPLICATION_ID, {
    "$select": ["id", "device_name"], 
    "$filter": { 
        "device_tag": {
            "$any": {
                "$alias": "tag",
                "$expr": {
                    "tag": {
                        "tag_key": 'TAG_KEY'
                    }
                }
            }
        }
    }
})