# Get Device Information

**URL:** <https://forum.bondhome.io/t/get-device-information/1229>\
**Category:** Uncategorized\
**Created:** [January 18, 2020, 2:16pm UTC](https://forum.bondhome.io/t/get-device-information/1229 "2020-01-18T14:16:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 18, 2020, 2:16pm UTC](https://forum.bondhome.io/t/get-device-information/1229/1 "2020-01-18T14:16:13Z")

</div>

Can the json reply format for “/v2/devices” be changed? I think the device ids should be on left side - not right side, i.e. instead of

```auto
{"_":"f7e407f1","79135791":{"_":"599b0fc5"}}

```

the reply should be something like:

```auto
{"_":"f7e407f1","id":"79135791"}

```

To explain the problem, when I parse json reply I convert the json string to C# class, so for your implementation it’s impossible -

```auto
public class __invalid_type__ 79135791
{
    public string _ { get; set; }
}

public class RootObject
{
    public string _ { get; set; }
    public __invalid_type__ 79135791 __invalid_name__ 79135791 { get; set; }
}

```

Using my suggestion {"\_":“f7e407f1”,“id”:“79135791”}:

```auto
public class RootObject
{
    public string _ { get; set; }
    public string id { get; set; }
}

```

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 18, 2020, 2:28pm UTC](https://forum.bondhome.io/t/get-device-information/1229/2 "2020-01-18T14:28:47Z")

</div>

Or to avoid breaking changes - another option is to add a new request i.e. “/v2/devicelist” which will return a whole list of devices with all device info, also to avoid two-stage requests to get device info. I don’t think it’s a huge overhead because nobody is going to have 1000’s of devices…

---

<div class="post-metadata">

**Author:** ![marcio](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/marcio/32/210_2.png) [@marcio](https://forum.bondhome.io/u/marcio)\
**Post date:** [January 18, 2020, 5:45pm UTC](https://forum.bondhome.io/t/get-device-information/1229/3 "2020-01-18T17:45:22Z")

</div>

Unfortunately we can’t change it, since there’s a lot of logic dependent on this API.  
What I suggest to you is work with json object, or dictionaries, until you have expanded the whole object (queried all topics). Then you can parse it to your C# class later. That’s what we do on the mobile apps 😉

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 18, 2020, 6:37pm UTC](https://forum.bondhome.io/t/get-device-information/1229/4 "2020-01-18T18:37:50Z")

</div>

As I said, you can add a **new** request i.e. “/v2/devicelist” to avoid breaking changes

---

<div class="post-metadata">

**Author:** ![alanchow](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/alanchow/32/182_2.png) [@alanchow](https://forum.bondhome.io/u/alanchow)\
**Post date:** [January 18, 2020, 8:34pm UTC](https://forum.bondhome.io/t/get-device-information/1229/5 "2020-01-18T20:34:38Z")

</div>

It’s JSON. Doesn’t matter which order it is in as you just convert it to an array, dictionary, table, or whatever your programming language supports.

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 3:56am UTC](https://forum.bondhome.io/t/get-device-information/1229/6 "2020-01-19T03:56:08Z")

</div>

It does matter. Json id dictionary “keyword =\> value”. So, to be able to get the device id the reply should be “ID : xxxx”. Then you get the id like this: json[ID].

But in current implementation the device id is the “keyword”. So how do I get it?

I know, I can parse anything, but why bother? It’s wrong implementation. The strings on the left should be **known** constants.

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 3:58am UTC](https://forum.bondhome.io/t/get-device-information/1229/7 "2020-01-19T03:58:20Z")

</div>

And BTW, because there are multiple devices - it should be a list i.e.

```auto
{"ids":["xxx","yyy"]}

```

```auto
public class RootObject
{
    public List<string> ids { get; set; }
}

```

---

<div class="post-metadata">

**Author:** ![merck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/merck/32/1238_2.png) [@merck](https://forum.bondhome.io/u/merck)\
**Post date:** [January 19, 2020, 8:39am UTC](https://forum.bondhome.io/t/get-device-information/1229/8 "2020-01-19T08:39:53Z")

</div>

What you want is something like this (pseudo-code):

```auto
json_obj = get('v2/devices')
dev_id_list = [id for id in json_obj.keys() if not id.startswith('_')]

```

Expl: `v2/devices` is an emumeration, so all children are devices with the ID in the keys, with the exception of “hidden” keys which always start with an underscore.

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 8:42am UTC](https://forum.bondhome.io/t/get-device-information/1229/9 "2020-01-19T08:42:20Z")

</div>

Haha, that’s what I just did:

```auto
ids = (from id in response where (string)id != "_" select (string)id).ToList();

```

But better cast response to:

```auto
class DevicesResponse : List<Dictionary<string,object>>
{
}

```

Still, would be **much better** to just get a list of devices (not just ids)

---

<div class="post-metadata">

**Author:** ![merck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/merck/32/1238_2.png) [@merck](https://forum.bondhome.io/u/merck)\
**Post date:** [January 19, 2020, 8:45am UTC](https://forum.bondhome.io/t/get-device-information/1229/10 "2020-01-19T08:45:40Z")

</div>

Bond firmware is highly portable and needs to be able to be run on many platforms. If we add just one new API, we are committing long-term to supporting it on millions of connected appliances. Thus, we keep the API as simple as possible!

But, we do need to create some better “getting started” content on how to use the API in typical scenarios… how to get device lists for example. Examples would be necessity be in some language… Python probably…

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 8:53am UTC](https://forum.bondhome.io/t/get-device-information/1229/11 "2020-01-19T08:53:15Z")

</div>

I reckon it’s even better to provide a library (Python, Java, C#, C++) - so you don’t need to explain the API details much. I know - it’s a bit of work, but for end users it’s huge help. Like [Google Calendar API](https://developers.google.com/calendar/v3/reference).

When I finish my HomeSeer plugin I can provide my feedback on your documentation, if you don’t mind.

---

<div class="post-metadata">

**Author:** ![alanchow](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/alanchow/32/182_2.png) [@alanchow](https://forum.bondhome.io/u/alanchow)\
**Post date:** [January 19, 2020, 10:37am UTC](https://forum.bondhome.io/t/get-device-information/1229/12 "2020-01-19T10:37:26Z")

</div>

We wrote 4 drivers for 4 different control systems using lua, TCL and javascript. The API works and is fine as is. It is actually quite detailed in comparision to the hundreds of other APIs we encounter every year.

This is how we do the initial setup. This gives us all the details we need to get started (minus polling/udp feedback/control which i can get into if you need more tips - though that is pretty straight forward).

1. mDNS query (\_bond.\_tcp.local) for bond device (limit by Bond ID in case there are multiple)
2. We do a get version which we use for logs - so that our users can report back details for our support desk (/v2/sys/version)
3. Do a get token if no token is present (/v2/token)
4. Do a get devices (/v2/devices)
5. for each device get the device’s details (/v2/devices/deviceID)
6. for each device get the device’s properties (/v2/devices/deviceID/properties)

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 10:54am UTC](https://forum.bondhome.io/t/get-device-information/1229/13 "2020-01-19T10:54:47Z")

</div>

> [@alanchow](#):
>
> The API works and is fine as is

That’s because you know how to use it. “Any software is user friendly if you know which button to press”.

Sure, I already worked out the sequence, but it took me 2 days.

Instead of just

```auto
protected virtual bool GetStatus()
{
    GetVersion();

    if(String.IsNullOrEmpty(Token))
        GetToken();

    if (!String.IsNullOrEmpty(Token))
        ChildDevices = GetDevices();

    return true;
}

```

> [@alanchow](#):
>
> We wrote 4 drivers for 4 different control systems using lua, TCL and javascript.

That’s exactly my point! You could already have your libraries in 4 different languages! Not only for “some users” - just for your selves in the first place. That’s how I work - create a library first. But it’s up-to-you anyways.

---

<div class="post-metadata">

**Author:** ![alanchow](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/alanchow/32/182_2.png) [@alanchow](https://forum.bondhome.io/u/alanchow)\
**Post date:** [January 19, 2020, 11:30am UTC](https://forum.bondhome.io/t/get-device-information/1229/14 "2020-01-19T11:30:19Z")

</div>

The point I’m trying to make is that what the guys have done is perfectly fine.

We had 3 different developers at our company work on 4 different integrations/home automation systems.

The documentation is good and provides everything you need to do the work.

Sure the Olibra guys could make it even easier by doing the work for you but I would rather them do what their good at and that’s further improving integration of RF products.

---

<div class="post-metadata">

**Author:** ![alexbk66](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@alexbk66](https://forum.bondhome.io/u/alexbk66)\
**Post date:** [January 19, 2020, 11:34am UTC](https://forum.bondhome.io/t/get-device-information/1229/15 "2020-01-19T11:34:18Z")

</div>

ok, it was just a suggestion - not a subject for discussion. That’s a common excuse “we don’t have time to do it properly”. And believe me - I’ve seen it many times in my 30 years in the industry.

---

<div class="post-metadata">

**Author:** ![merck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/merck/32/1238_2.png) [@merck](https://forum.bondhome.io/u/merck)\
**Post date:** [January 20, 2020, 4:41pm UTC](https://forum.bondhome.io/t/get-device-information/1229/16 "2020-01-20T16:41:52Z")

</div>

> [@alexbk66](#):
>
> I can provide my feedback on your documentation, if you don’t mind.

Specific feedback/suggestions on how to improve the API docs is welcome!

---

<div class="post-metadata">

**Author:** ![residualimages](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/residualimages/32/74_2.png) [@residualimages](https://forum.bondhome.io/u/residualimages)\
**Post date:** [January 20, 2020, 5:00pm UTC](https://forum.bondhome.io/t/get-device-information/1229/17 "2020-01-20T17:00:00Z")

</div>

> [@merck](#):
>
> Specific feedback/suggestions

Could we, as a community, try to use something like [this topic](https://forum.bondhome.io/t/api-documentation-requests/) to track these so @merck and crew have a single place to go, versus 50,000 unique topics? 😀

---

<div class="post-metadata">

**Author:** ![merck](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.bondhome.io/merck/32/1238_2.png) [@merck](https://forum.bondhome.io/u/merck)\
**Post date:** [January 20, 2020, 5:06pm UTC](https://forum.bondhome.io/t/get-device-information/1229/18 "2020-01-20T17:06:09Z")

</div>

Better yet, here’s a repo with the source code to the docs. [https://github.com/bondhome/api-v2](https://github.com/bondhome/api-v2)

Best way to contribute: Open a PR there with a fix/improvement.

Or: Open an issue on that repo.
