I would like to create a script that automatically creates a droplet.
This script will have to be on my site.
For example, when a customer orders a VPS from my site via a script, the droplet will be created and the data to access it sends them by mail.
Is it possible?

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.

×
2 answers

@Dennys - Absolutely! You can use one of the available third-party libraries, such as the one linked to by @ryanpq (which is a very nice library – I’ve used it myself), or you can implement your own custom wrapper around DigitalOcean’s API (I’ve done this as well).

With PHP, you have a few options if you choose to go the custom route over using an existing third-party library. The most common method that I’ve seen implemented is by using PHP’s cURL library (link) – you could also use PHP’s Streams library (link).

Ultimately, I’d go with Streams over cURL, though that’s my personal preference. There’s numerous options for cURL and while I’ve used it in the past to access API’s, Streams seems to be a much cleaner way of doing the same thing.

stream_context_create
http://php.net/manual/en/function.stream-context-create.php

stream_get_contents
http://php.net/manual/en/function.stream-get-contents.php

This is absolutely possible. We provide an API to most control panel features. While we do not maintain an official PHP library for our API a great third party library is available here.

These links will provide some additional information on the API.

If you have any questions or run into any problems let me know :)

Submit an Answer