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.

get main domain using php api2

Discussion in 'cPanel Developers' started by hirani89, Mar 5, 2015.

  1. hirani89

    hirani89 Registered

    Joined:
    Feb 10, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hey everyone,

    Ive used the method provided in the API2 docs to get the main domain the script is running through. I dont get any errors but nothing is returned when i use the api. This is what i have.

    PHP:
    $base_domain $GLOBALS['cpanel']->api2(
            
    'DomainLookup''getmaindomain'
        
    );
    And this is how I'm trying to get the domain from the json output:

    PHP:
    $url_array json_decode($base_domaintrue);
    $url $url_array['cpanelresult']['data'][0]['main_domain'];
    Can some please tell me the problem with my code.

    Regards
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. hirani89

    hirani89 Registered

    Joined:
    Feb 10, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hey Michael,

    Got it to work... Apparently I don't have to json_decode the output from the api. I thought a json object is returned so I had to decode it. Thats what the api says..

    Anyways thanks for the help though.

    Regards.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page