# \[api-spec\] Create a machine/host programmatically via Rancher API

**URL:** <https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447>\
**Category:** Rancher 1.x\
**Created:** [September 11, 2015, 1:22pm UTC](https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447 "2015-09-11T13:22:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manadagr](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@manadagr](https://forums.suse.com/u/manadagr)\
**Post date:** [September 11, 2015, 1:22pm UTC](https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447/1 "2015-09-11T13:22:30Z")

</div>

Hello. I want to use the Rancher API to create a host (an ec2 instance via docker machine). I found this resource `/v1/projects/1a5/machines` that listed my existing machines in this environment. I’m doing a POST via curl and getting a 422 response with some JSON containing an error code and message `“DriverConfigExactlyOneRequired”`. What looks like the same request, via hitting the Create button while browsing the API, works fine and sets up the ec2 instance. I can do an HTTP DELETE on machines via curl but can’t create them. This is my curl command:

```
curl -v -u $RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"name": "my-aws-host", "amazonec2config": {"accessKey": "XXXXXXXX”, "secretKey": “XXXXXXXXX”, "ami": "ami-45d8a532", "instanceType": "t2.micro", "region": "eu-west-1", "securityGroup": "rancher-machine", "zone": "a", "vpcId": “xxxxxxx”}}’ http://my.rancher.server:8080/v1/projects/1a5/machines

```

and response body is:

```
{"id":"387965ba-25a1-4431-8924-516a24781842","type":"error","links":{},"actions":{},"status":422,"code":"DriverConfigExactlyOneRequired","message":"DriverConfigExactlyOneRequired","detail":null}

```

Am I missing something from my curl command? Thanks and great work with the API I must say.

---

<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:** [September 11, 2015, 5:47pm UTC](https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447/2 "2015-09-11T17:47:01Z")

</div>

Capital “C” in `amaconec2Config`.

---

<div class="post-metadata">

**Author:** ![manadagr](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@manadagr](https://forums.suse.com/u/manadagr)\
**Post date:** [September 14, 2015, 10:38am UTC](https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447/3 "2015-09-14T10:38:05Z")

</div>

Doh! Sorry now working. Thanks.

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [September 14, 2015, 5:20pm UTC](https://forums.suse.com/t/api-spec-create-a-machine-host-programmatically-via-rancher-api/447/4 "2015-09-14T17:20:23Z")

</div>


