PHP Cloudways API SDK: Manage sites hosted in Cloudways using its API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (28)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-09-04 (6 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 8 This week: 8All time: 10,407 This week: 23Up
Version License PHP version Categories
cloudwaysapisdk 1.0The PHP License5Hosting
Description Author

This package can be used to manage sites hosted in Cloudways using its API.

It can send HTTP requests to the Cloudways API Web server to perform several types of requests. Currently it can:

- Manage hosted application DNS records
- Manage the access of Git repositories using SSH keys
- Manage integrations with other systems
- Manage the alerts of the current account
- Search in the knowledge base
- List the available server resources
- Manage hosted projects
- Manage SSL certificates and other security resources
- Manage hosting servers
- Manage the Varnish caching server

Picture of Ahmed Khan
Name: Ahmed Khan <contact>
Classes: 4 packages by
Country: Pakistan Pakistan
Innovation award
Innovation award
Nominee: 1x

Details

A PHP-SDK for Cloudways API.

You can clone it to start working on it or use composer to install it.

Type the following command to install SDK using composer

$composer require ahmedkhan847/cloudwaysapiphpsdk

Or create a new file name it composer.json and paste the following code in it.

    {
    	"require": {
    		        "ahmedkhan847/cloudwaysapiphpsdk" : "1.0.0.x-dev"
    	    }
    }

Cloudways API PHP-SDK also provides you two function to check the status of operation id. The first is getOperation($operationid) which will return the result from which you have to extract whether the operation is completed. The second one is getOperationResult($operationid, $wait) which take the $operationid and $wait parameter (in seconds) and returns true when the operation is completed. If it reaches the maximum execution time for PHP, the code will stop and you need to run the function again.

To learn more about using it read the following guide: Possibilities of Cloudways API PHP-SDK.

Creating a New Server

#!php

<?php
require "vendor/autoload.php";

use Cloudways\Server\Server;

$server = new Server();
$server->SetEmail("ahmed.khan@cloudways.com");
$server->SetKey("gR1YywOMN2gG8L0FZC6Rd3QSsr0jlM");

$value['cloud'] = "do";
$value['region'] ="lon1";
$value['instance_type'] ="512MB";
$value['memory_size'] ="";
$value['application'] ="phpstack";
$value['app_version'] ="5.4";
$value['project_name'] ="";
$value['this->server_label'] ="abc";
$value['app_label'] ="abc";
$value['db_volume_size'] ="";
$value['data_volume_size'] ="";

$result = $server->create_server($value);

Using this SDK in Laravel

For laravel define email and api key in .env file

CW_EMAIL=ahmed.khan@cloudways.com
CW_API_KEY=gR1YywOMN2gG8L0FZC6Rd3QSsr0jlM

Then in your control add the namespace and start using it.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Cloudways\Lists\Lists;

class ApiController extends Controller
{
    /
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $list = new Lists();
        $result = [];
        $result[] = $list->getServerRegions();
        $result[] = $list->getCloudProviders();
        $result[] = $list->getServerSizes();
        $result[] = $list->getApps();
        $result[] = $list->getPackages();
        $result[] = $list->getSettings();
        $result[] = $list->getBackupFrequencies();
        $result[] = $list->getCountries();
        $result[] = $list->getMonitorDurations();
        $result[] = $list->getMonitorTargets();
        return $result;
    }
}
?>
  Files folder image Files  
File Role Description
Files folder imageAPITestFiles (1 directory)
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

 Version Control Unique User Downloads Download Rankings  
 100%
Total:8
This week:8
All time:10,407
This week:23Up

For more information send a message to info at phpclasses dot org.