# Create a label via the API

**URL:** <https://forums.suse.com/t/create-a-label-via-the-api/3789>\
**Category:** Rancher 1.x\
**Created:** [August 23, 2016, 7:35pm UTC](https://forums.suse.com/t/create-a-label-via-the-api/3789 "2016-08-23T19:35:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fraser\_Goffin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/fraser_goffin/32/6608_2.png) [@Fraser\_Goffin](https://forums.suse.com/u/Fraser_Goffin)\
**Post date:** [August 23, 2016, 7:35pm UTC](https://forums.suse.com/t/create-a-label-via-the-api/3789/1 "2016-08-23T19:35:56Z")

</div>

I use the API to auto-register docker hosts to a Rancher environment and it works well. Hosts in our case are maintained in AWS via an auto-scaling group which runs a user-data script to do the work. We have a number of these for different types of hosts (see below).

However, I also create a number of differently categorised hosts which are differentiated by a label. Those labels are used by scheduling rules. Problem is I have been unable to find a way of creating the label at the time I auto-register the host.

Taking an example, let’s say I want to create a label called HOST\_TYPE with a value of LB. How can I do that at the same time as registering the host, fully automated ?

Regards

Fraser.

---

<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:** [August 23, 2016, 9:04pm UTC](https://forums.suse.com/t/create-a-label-via-the-api/3789/2 "2016-08-23T21:04:17Z")

</div>

You can set host labels by setting an environment variable in the docker run command for the agent with url-encoded pairs, e.g., `-e CATTLE_HOST_LABELS='foo=bar&baz=qwer'`. The custom Add Host UI also has an option for it and shows you the command.

---

<div class="post-metadata">

**Author:** ![Fraser\_Goffin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/fraser_goffin/32/6608_2.png) [@Fraser\_Goffin](https://forums.suse.com/u/Fraser_Goffin)\
**Post date:** [August 23, 2016, 9:31pm UTC](https://forums.suse.com/t/create-a-label-via-the-api/3789/3 "2016-08-23T21:31:45Z")

</div>

Ah yes, I had forgotten about that, perfect, thx Vincent.

For the benefit of others it’s also documented here (RTFM) : [http://docs.rancher.com/rancher/v1.2/en/hosts/custom/](http://docs.rancher.com/rancher/v1.2/en/hosts/custom/)
