When creating a new Droplet, the IP addresses are not assigned until after it has been provisioned. So they are not included in the initial response from the API. Though you can retrieve them programmatically. The JSON response to the create API call will provide a “links” object that can be used to check on the status of the create event. For example, it might look like:
{
"droplet": {
"id": 3164494,
"name": "example.com",
"memory": 512,
"vcpus": 1,
"disk": 20,
"locked": true,
"status": "new",
"kernel": {
"id": 2233,
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
"version": "3.13.0-37-generic"
},
"created_at": "2014-11-14T16:36:31Z",
"features": [
"virtio"
],
"backup_ids": [
],
"snapshot_ids": [
],
"image": {
},
"size": {
},
"size_slug": "512mb",
"networks": {
},
"region": {
},
"tags": [
]
},
"links": {
"actions": [
{
"id": 36805096,
"rel": "create",
"href": "https://api.digitalocean.com/v2/actions/36805096"
}
]
}
}
The link to the action object (in this case https://api.digitalocean.com/v2/actions/36805096
) can then be called to see if the even is completed. Just check for the status field in the reply:
{
"action": {
"id": 36804636,
"status": "completed",
"type": "create",
"started_at": "2014-11-14T16:29:21Z",
"completed_at": "2014-11-14T16:30:06Z",
"resource_id": 3164444,
"resource_type": "droplet",
"region": "nyc3",
"region_slug": "nyc3"
}
}
Once the status reports completed
rather than in-progress
, you can retrieve the IP addresses by querying the Droplet’s API endpoint.
You can find out more about using the actions endpoint and see a full example in this tutorial: