The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JSON-API calls to make new subdomain, email, ftp, and database help

Discussion in 'cPanel Developers' started by s2xi, Aug 2, 2011.

  1. s2xi

    s2xi Member

    Joined:
    Jul 8, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hey guys, I cant' seem to find sufficient documentation on where to find the specific modules and functions to be able to create new subdmains, ftp account, email, and new database along with user and assigning a user to a database.

    I am using cURL to submit my queries and have a sample call that will lookup the bandwith of my server


    PHP:
    $query "http://".$this->domain.":".$this->port."/json-api/cpanel?cpanel_jsonapi_module=StatsBar&cpanel_jsonapi_func=stat&display=diskusage&domain=".$this->domain;

    this out puts something like:

    PHP:
    Array ( [diskused] => 11.7 [diskquota] => unlimited [diskleft] => unlimited [bandwidthcount] => 47.3 [bandwidthmax] => unlimited [bandwidthleft] => unlimited 
    so I am seeing that my cURL calls are working properly. But now I am looking to see how I can use my script to make the accounts I mentioned above.

    Where can I look for the cpanel_jsonapi_module and cpanel_jsonapi_func

    or if someone has a resource where such scripts have already been made I would welcome the help.

    I chose to use the JSON-API because it was said that its faster than using the XML-API.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi s2xi,

    All the info you need is at skd.cpanel.net. Specifically, API2 and API1. Those links will list the various modules...which links to a page for all the functions for that module. It should be easy for you find what you need from there; give a holler if you need anything else.

    Regards,
    -DavidN
     
  3. s2xi

    s2xi Member

    Joined:
    Jul 8, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    I was looking for that link but had lost and forgot how I ended up there.

    Can you please give me an example url call for how the add a subdomain would look like so that i can base my learning off it.

    Thank you
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi s2xi,

    Below is the sample URL you asked for; I've broken it up for readability
    Code:
    /json-api/cpanel?
    cpanel_jsonapi_module=SubDomain&
    cpanel_jsonapi_func=addsubdomain&
    cpanel_jsonapi_apiversion=2&
    dir=public_html/newsub/&
    rootdomain=dave.com&
    subdomain=lil
    
    this should give you a new subdomain called lil.dave.com who's docroot is ~/public_html/newsub/

    If you're not aware, we have a PHP client class that will do all the cURL and URL construction for you. It is available here: https://github.com/CpanelInc/xmlapi-php

    Here's an example of subdomain creation with PHP XML-API client class:
    PHP:
    include "xmlapi.php";

    $auth_user 'me';
    $auth_pass 'my_secret';

    $server '10.1.1.1';

    $json_client = new xmlapi($server);

    $json_client->set_output('json');
    $json_client->set_port(2083);
    $json_client->password_auth($auth_user$auth_pass);

    //$json_client->set_debug(1); // for debugging

    $args = array(
        
    'dir'       => 'public_html/newsub',
        
    'rootdomain' => 'dave.com',
        
    'subdomain' => 'lil',
    );

    $result $json_client->api2_query$auth_user'SubDomain''addsubdomain'$args);
    Best Regards,
    -DavidN
     
Loading...

Share This Page