Unbind all devices

Unbind all devices.

Code sample

C#

public static object UnbindAllDevices(
    string projectId, string cloudRegion, string registryId)
{
    var cloudIot = CreateAuthorizedClient();
    // The resource name of the location associated with the key rings.
    var parent = $"projects/{projectId}/locations/{cloudRegion}/registries/{registryId}";
    try
    {
        var devices = cloudIot
            .Projects
            .Locations
            .Registries
            .Devices
            .List(parent)
            .Execute()
            .Devices;
        Console.WriteLine("Devices: {0}", parent);

        if (devices != null)
        {
            foreach (var response in devices)
            {
                UnbindDeviceFromAllGateways(cloudIot, projectId,
                cloudRegion, registryId, response.Id);
            }
        }
        else
        {
            Console.WriteLine("No bound device found.");
        }
    }
    catch (Google.GoogleApiException e)
    {
        Console.WriteLine(e.Message);
        return e.Error.Code;
    }
    return 0;
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.