SOLVED Create database using PHP API

jason213

Registered
Dec 1, 2012
4
1
1
cPanel Access Level
Reseller Owner
Hello,
in older versions of cpanel im able to creat database by using the cpanel login using a php script, now in new versions i see that is not possible.
I see that you have the uapi that have that option but i can´t find any working example,
can you help me here can i find the working examples to creat a database using the uapi?
Thanks,
Bruno
 

jason213

Registered
Dec 1, 2012
4
1
1
cPanel Access Level
Reseller Owner
Hello,
thank for you reply.
for other persons that are looking for the same solution, i have found the code below that work for me.
I don´t understand why cpanel is too much complicated to request a simple database, i hope in the future
cpanel don´t change code again, because the suport from their side simple don´t exist and cpanel is not a cheap solution.
We developers don´t have time to deal with changes like this without decent suport,
this is my opinion, i use others panel solutions for years and i don´t have this problem in other solutions next time i have a problem i will think about to change control painel provider.

Thanks,
Bruno
Code:
    $server_login_link = 'url';
    $whmusername = 'user';
    $hash = 'token';
    $query = "https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=createdb&db=example_database";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);

    $header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$hash);
    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
    curl_setopt($curl, CURLOPT_URL, $query);

    $result = curl_exec($curl);
    print_r(json_decode($result));
 
Last edited by a moderator:
  • Like
Reactions: cPanelMichael