Share via


DeviceManagementClient.GetGroups(String, RequestContext) Method

Definition

Gets a list of all device groups. The $default group will always be returned first.

public virtual Azure.Pageable<BinaryData> GetGroups (string orderBy = default, Azure.RequestContext context = default);
abstract member GetGroups : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
override this.GetGroups : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
Public Overridable Function GetGroups (Optional orderBy As String = Nothing, Optional context As RequestContext = Nothing) As Pageable(Of BinaryData)

Parameters

orderBy
String

Orders the set of groups returned. You can order by groupId, deviceCount, createdDate, subgroupsWithNewUpdatesAvailableCount, subgroupsWithUpdatesInProgressCount, or subgroupsOnLatestUpdateCount.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The Pageable<T> from the service containing a list of BinaryData objects. Details of the body schema for each item in the collection are in the Remarks section below.

Exceptions

Service returned a non-success status code.

Examples

This sample shows how to call GetGroups and parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetGroups())
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("groupId").ToString());
    Console.WriteLine(result.GetProperty("groupType").ToString());
    Console.WriteLine(result.GetProperty("createdDateTime").ToString());
}

This sample shows how to call GetGroups with all parameters, and how to parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetGroups("<orderBy>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("groupId").ToString());
    Console.WriteLine(result.GetProperty("groupType").ToString());
    Console.WriteLine(result.GetProperty("createdDateTime").ToString());
    Console.WriteLine(result.GetProperty("deviceCount").ToString());
    Console.WriteLine(result.GetProperty("subgroupsWithNewUpdatesAvailableCount").ToString());
    Console.WriteLine(result.GetProperty("subgroupsWithUpdatesInProgressCount").ToString());
    Console.WriteLine(result.GetProperty("subgroupsWithOnLatestUpdateCount").ToString());
    Console.WriteLine(result.GetProperty("deployments")[0].ToString());
}

Remarks

Below is the JSON schema for one item in the pageable response.

Response Body:

Schema for GroupsListValue:

{
              groupId: string, # Required. Group identity. This is created from the value of the ADUGroup tag in the Iot Hub's device/module twin or $default for devices with no tag.
              groupType: "IoTHubTag" | "DefaultNoTag", # Required. Group type.
              createdDateTime: string, # Required. Date and time when the update was created.
              deviceCount: number, # Optional. The number of devices in the group.
              subgroupsWithNewUpdatesAvailableCount: number, # Optional. The count of subgroups with new updates available.
              subgroupsWithUpdatesInProgressCount: number, # Optional. The count of subgroups with updates in progress.
              subgroupsWithOnLatestUpdateCount: number, # Optional. The count of subgroups with devices on the latest update.
              deployments: [string], # Optional. The active deployment Ids for the group
            }

Applies to