Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    I am happy to see you were able to resolve the issue. Thank you for updating us with the outcome.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice