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

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.

1 Like

Capital “C” in amaconec2Config.

Doh! Sorry now working. Thanks.