Avatar

Unable to get Devices by Group Name, returns NullReferenceException

0

I am trying to return devices based on a Group Name.

When ever I try to, it throws an "NullReferenceException" exception.

 

Using the .NET SDK, here is the code I am running:

 

This works, it gets the Group by it's name.  Then does a device search using the GroupId that was returned.

api.Authenticate();

GroupSearch groupSearch = new GroupSearch
{
Name="55818"
};
IList<Group> groups = api.Call<IList<Group>>("Get", typeof(Group), new { search = groupSearch });
Console.WriteLine(groups.Count);

DeviceSearch deviceSearchByGroupId = new DeviceSearch
{
Groups = new List<GroupSearch>
{
new GroupSearch{Id=groups[0].Id}
}
};
IList<Device> devicesByGroupId = api.Call<IList<Device>>("Get", typeof(Device), new { search = deviceSearchByGroupId });

 

This is what I am trying that doesn't work.  This tries to get devices on a group based on the Group Name, not the Group Id.

api.Authenticate();

DeviceSearch deviceSearchByGroupName = new DeviceSearch
{
Groups = new List<GroupSearch>
{
new GroupSearch{Name="55818"}
}
};
IList<Device> devicesByGroupName = api.Call<IList<Device>>("Get", typeof(Device), new { search = deviceSearchByGroupName });

 

 

Any thoughts?

Ben Haynie

Please sign in to leave a comment.

2 comments

1
Avatar

Hi Ben,

Id is the only parameter that can be used for a GroupSearch inside of a DeviceSearch.  You can find more details on our API reference page.  Here is the relevant section:

Your workflow in the first snippet is the correct way to approach pulling devices by group based on group name.

Kaylan Mettus 1 vote