# Which version of api? to CREATE/DELETE

**URL:** <https://forums.suse.com/t/which-version-of-api-to-create-delete/4850>\
**Category:** Rancher 1.x\
**Created:** [December 8, 2016, 3:25pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850 "2016-12-08T15:25:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 3:25pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/1 "2016-12-08T15:25:11Z")

</div>

Running rancher 1.14 using marathon on mesos, added vamp/consul/elastic search as well. Been creating hosts in rancher manually. Been using catalogs in rancher UI to start container services listed above. NOW started building a microservice in node.js to hit marathon and rancher and vamp with CRUD. The reading of rancher endpoints works great, thx. Using /V1 api endpoints that come up in rancher 1.14 API-\>\> advanced --\>\> account keys endpoint.

Now I want to CREATE and DELETE hosts from Rancher API. Instructions online not for /V1 but for /V2-beta???  
[http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/host/](http://docs.rancher.com/rancher/v1.2/en/api/v2-beta/api-resources/host/)  
Have been trying to use examples and nothing is working. Been aiming at /V1 version of endpoints that work perfectly for reads.I am using account account keys BTW for security.

1. Does V2-beta work with Rancher 1.1.4? Or do I have to upgrade to 1.2 to have those work?
2. Does api version /V1 NOT support host/create and host/delete?
3. DELETE /V1 endpoints are returning an error that METHOD is not supported. Is that an api version issue or is there a special syntax required for deleting hosts (or physical hosts)? or do I delete Instances?
4. CREATE POST continues to tell me that there is a format error in my json file I created to hopefully create a fifth identical host in the mesos cluster under rancher. Is there a working file I can download to test to build an AWS instance that you know works correctly?

Thanks

---

<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:** [December 8, 2016, 7:16pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/2 "2016-12-08T19:16:12Z")

</div>

v2-beta is available only in `1.2.x` (starting around `-pre2` or `-pre3`). There are separate docs pages for `v1.1`.

In 1.1/API v1, you would create a `machine` resource with `POST /v1/projects/<project id>/machines`. That creates the virtual machine in the provider and starts the rancher agent, which eventually reports in and causes a `host` resource to show up. The UI displays both `machines` and `hosts` on the same screen to make them look like one thing.

In 1.2/API v2-beta, `machine` and `host` are combined together so you create a `host` resource directly and do not have to track the 2 separate but related resources.

DELETE is correct but not always available. The host must first be first deactivated using the `deactivate` action.

Try pasting your JSON into a linter like [http://jsonlint.com/](http://jsonlint.com/) . It must be actually valid JSON that conforms to the standard, which is stricter than some other parsers allow. For example map keys must be quoted strings, strings in general must be double quoted (not single), an extra comma after the last item in an array or map is not allowed, etc.

---

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 7:40pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/3 "2016-12-08T19:40:09Z")

</div>

excellent thanks

whats the url for the V1.14 v1 api docs?

---

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 7:46pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/4 "2016-12-08T19:46:27Z")

</div>

[http://docs.rancher.com/rancher/v1.0/en/api/v1/api-resources/host/#deactivate](http://docs.rancher.com/rancher/v1.0/en/api/v1/api-resources/host/#deactivate)  
so for v1 to delete is host/deactivate then machine/delete, correct?

---

<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:** [December 8, 2016, 8:13pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/5 "2016-12-08T20:13:18Z")

</div>

Yes; there may be a bug with using v1 in 1.2 to create a machine never showing up as a host; @sangeethah was trying to reproduce it yesterday.

---

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 8:21pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/6 "2016-12-08T20:21:42Z")

</div>

I am just running 1.14 and api v1, not mixing them (as I saw issues on upgrading for the moment).

Thanks again for answering my questions,

1)So the deactivation id is the INTEGER returned by GET /machines or GET /hosts?  
2) Deactivation is a POST and Remove is a DELETE, correct?  
3)The base URL is /V! or /V1/Project/{projectid}?

(so far have not gotten the combo right ☹

---

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 8:49pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/7 "2016-12-08T20:49:59Z")

</div>

when I was trying to remove a host I would get a 405 error  
now when I try and deactivate a host I get 404 errors

---

<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:** [December 8, 2016, 9:56pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/8 "2016-12-08T21:56:08Z")

</div>

1. IDs are all strings; you should treat them as arbitrary data, but in the normal config they are of the form “1”+“one or more letters denoting the resource type”+auto incrementing number. So “1h1” is a host", “1m1” is a machine, etc.

2. The clean way to do things is to GET the resource you’re interested in first. Then Actions (like deactivate) are a POST to the URL listed in the `actions` map, and delete is the DELETE method to the `links` map -\> `self` entry.

3. “Environment” in the UI === `project` in the API. If you’re using an API key tied to the specific environment (you probably are in 1.1.x) then the project ID is already known so you can use `/v1/hosts`. If you have a key tied to a user (or access control is off and you’re doing no authentication) then you have access to multiple environmnets and need to specify which one you’re referring to by using `/v1/projects/<project id>/hosts`.

---

<div class="post-metadata">

**Author:** ![pvcon13](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@pvcon13](https://forums.suse.com/u/pvcon13)\
**Post date:** [December 8, 2016, 11:55pm UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/9 "2016-12-08T23:55:02Z")

</div>

Thanks, you saved me.

I looked at the schemas and they said Integer not string for ID.  
When I used strings for GET filters they bombed  
When I removed the 1 + prefix the GET filters (QS) they worked correctly  
So I assumed that you wanted all IDs as number/integers  
My bad/ So now I use Integers for QS id filters and strings for ids for deactivate and remove.

Next I work on the formating of the Create POST Json.

Thanks again Vincent 🙂

---

<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:** [December 9, 2016, 2:36am UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/10 "2016-12-09T02:36:53Z")

</div>

Yeah the schema is wrong for IDs… it’s because they _are_ actually integers. If you run a public cloud you probably don’t want everyone to know exactly how many hosts, containers, accounts, etc there are, so there’s a hook there to allow transforming the IDs to something that isn’t guessable/auto-incrementing. And to exercise that the default transform is “1”+“type letter”+num.

What filter are you trying to do on an ID? If you want a particular record by ID, then it’s just `/v1/projects/<project id>/<type>/<record ID>` and you’ll get back a single record (or 404). You don’t need to do /v1/project//type?id= (and get back a list of 0/1 thing). If you’re doing less than/greater than/etc then I’m surprised that even works…

---

<div class="post-metadata">

**Author:** ![ayden8](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@ayden8](https://forums.suse.com/u/ayden8)\
**Post date:** [September 9, 2017, 4:59am UTC](https://forums.suse.com/t/which-version-of-api-to-create-delete/4850/11 "2017-09-09T04:59:18Z")

</div>

Use this tool to validate: json formatter [https://jsonformatter-online.com](https://jsonformatter-online.com)  
Hope this help!
