# Name is null when adding a host via the API

**URL:** <https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744>\
**Category:** Rancher 1.x\
**Created:** [February 16, 2016, 5:31pm UTC](https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744 "2016-02-16T17:31:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebishop](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@ebishop](https://forums.suse.com/u/ebishop)\
**Post date:** [February 16, 2016, 5:31pm UTC](https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744/1 "2016-02-16T17:31:16Z")

</div>

After upgrading to 59, I found that the ‘name’ field is null when adding a host via the API. I’m adding a host to Openstack and passing in the host name. The host is added, but I had a check to verify the Rancher host information was added after the machine data was added. This check fails now - before the’name’ field was set in Rancher. I noticed that there is a “hostname” field that is populated with the name I passed to Openstack, so I’ll check that field for a match instead.

Is this a bug, or a change to the API?

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [February 16, 2016, 6:26pm UTC](https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744/2 "2016-02-16T18:26:42Z")

</div>

What do you mean by “passing in the host name”?

Previously the `name` was set by the agent to the Host’s `hostname` once on registration and then never updated if it changed, so you ended up with Host names that don’t match their actual hostnames.

The agent in 0.59 syncs the `hostname` field, so that it changes if the machine’s hostname changes. The UI then displays the `name` field if it is set and `hostname` if it’s not (and `(id)` if somehow there’s no `hostname` either).

So the net result is `name` will be null by default and `hostname` will be displayed for each Host, but the user can override it by setting a `name`.

---

<div class="post-metadata">

**Author:** ![ebishop](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@ebishop](https://forums.suse.com/u/ebishop)\
**Post date:** [February 16, 2016, 6:47pm UTC](https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744/3 "2016-02-16T18:47:21Z")

</div>

I pass the “name” in the json block of the Rancher API. Anyway, this seems like a recent change, so I thought I’d mention it. I have the information I need.

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [February 16, 2016, 7:06pm UTC](https://forums.suse.com/t/name-is-null-when-adding-a-host-via-the-api/1744/4 "2016-02-16T19:06:17Z")

</div>

oh I see, you’re adding a `machine` in the API, not a host… the name of the machine is given to `docker-machine`, which sets the `hostname` on the VM it creates to that, and then the hostname is read in by the Rancher agent and populates the `hostname` field. So yes, the name will be null there.

Basically if you want the name that is displayed by the UI for a host, you need something like

```javascript
function getName(host) {
  if ( host.name !== null ) {
    return host.name;
  } else if ( host.hostname !== null ) {
    return host.hostname;
  } else {
    return "(" + host.id + ")";
  }
}

```
