Vultr PHP Composer Library Updated!

Recently this week I took the opportunity with some well gifted downtime to update my composer library for Vultr’s API to the latest version. WIth this update comes a lot of code clean up as well as an easier configuration to use and “smarter” library.

To download the library, it will require a minimum of PHP 8 with json enabled. Using composer, simply run:

composer require dutchie027\vultr

After composer downloads the required libraries, it should trigger a quick library that will build out a local file called “vultr.ini” which will have some basic settings in it allowing the library to communicate with the API.

The minimum to use the library is the API key. That would make the .ini file look somewhat like the following:

[api]
TOKEN='8675309TOMMY30918IN'

The API process is really a two-step process. First you need to get your API token from My Vultr. Once you have the API Key, you need to ensure the IP address you’re coming from has access to use the API (located in the same place in your My Vultr Portal)

To load the library, simply call it by importing composer and then, if you created the .ini in a different directory, point the library to it:

Option 1 (“vultr.ini” in the root directory)

<?php

// require the composer library
require_once('vendor/autoload.php');

//make the connction to the API for use
$api = new dutchie027\Vultr\API();

print_r(json_decode($api->account()->getAccountInfo(), true));

Option 2 (having a “config.ini” renamed in a different directory):

<?php

// require the composer library
require_once('vendor/autoload.php');

//make the connction to the API for use
$api = new dutchie027\Vultr\API("/opt/config.ini");

print_r(json_decode($api->account()->getAccountInfo(), true));

If the above is correct, you should see a listing of your account info and all of the ACLs associated with it and what you can do with the API!

Good luck and have fun!