Connecting to Cloudways API via OAuth Access token

Posted by Fabian - 1 min read
Connecting to Cloudways API via OAuth Access token

Cloudays API Documentation

The Cloudways API docs can be found here: https://developers.cloudways.com/docs/

OAuth

Firstly make sure to add your API key and Cloudways username to the enviroment file, eg:

CW_API_KEY="*****************************"
CW_EMAIL_ADDRESS="email@domain.com"

Add to Web Route

In your Laravel Web Route add the following:

Route::get('create', function (){
    // Get value of an environment variable and assign to the $apiKey variable
    $apiKey = env('CW_API_KEY');
    
    // Assign the URL of the Cloudways API's OAuth access token endpoint to the variable
    $accessTokenAPI = 'https://api.cloudways.com/api/v1/oauth/access_token';
    
    // Sends a POST request to the Cloudways API's endpoint with two parameters
    $response = Http::post($accessTokenAPI, [
        'email' => env('CW_EMAIL_ADDRESS'),
        'api_key' => $apiKey,
    ]);
    
    // Dumping the body of the HTTP response
    dd($response->body());
});

View the Token

To view the generated token goto this slug: /create (eg. htts://domain.com/create)

This will display a token similar to below:

"{"access_token":"aaaaaaaabbbbbbbbccccccdddddddeeeeee","token_type":"Bearer","expires_in":3600}" // routes/web.php:26

Cloudays OAuth Access Token Documentation

The Cloudways API OAuth Access Token documentation can be found here: https://developers.cloudways.com/docs/#!/AuthenticationApi#getOAuthAccessToken

©2026 - Syntax by Wurkhouse | All Rights Reserved