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); } ?>
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $100 of credit to try our products over 60 days!