Report this

What is the reason for this report?

Can I assign a firewall while creating a droplet via API?

Posted on March 21, 2018

I would like to provision droplets for my clients via the API and everything works great except I don’t see anything in the documentation for assigning a cloud firewall while creating a droplet.

Is there any way to automatically do this at the same time? An example of the code I am currently using:


// Setup droplet details
$data = array(
"name" => "$hostname",
"region" => "$location",
"size" => "s-1vcpu-1gb",
"monitoring" => "true",
"image" => "centos-7-x64",
"user_data" => "$user_data",
);

# Convert droplet details into JSON
$data_string = json_encode($data);

// Setup actually sending to API
$ch = curl_init('https://api.digitalocean.com/v2/droplets');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Bearer $TOKEN",
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
);

$result = curl_exec($ch);

// Actually send to API and show result
print_r($result);

}    
?>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.