Can I assign a firewall while creating a droplet via API?
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); } ?>
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.×