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.

Authenticating with access hash instead of reseller password with cPanel API2

Discussion in 'cPanel Developers' started by devel, Feb 10, 2014.

  1. devel

    devel Member

    Joined:
    Sep 21, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Hello.

    I am trying to extract disk and bandwidth usage from cPanel accounts under a reseller. To this end, I am using the cPanel API2 StatsBar->stats->display. The problem I am having is authenticating. When I use the reseller password to log in to any account below the reseller, everything works fine. However, this seems like a bad solution as opposed to using access hashes. But when using the access hash of the reseller account instead (located in /home/reseller/.accesshash), I get access denied errors.

    Could anyone tell me what I am doing wrong? Am I not supposed to be using access hashes here? Is the use of reseller passwords the advocated and approved solution?

    Thanks a lot. My code is below.

    Devel.

    Code:
    		...
    		$cpCfg = array('cpanel' => array('service' => array('cpanel' => array(
    			'host' => 'ip goes here',
    			'user' => 'any cPanel account goes here',
    			//'password' => 'reseller password goes here'
    			'accesshash' => $access-hash-without-newlines-goes-here
    		))));
    		$cp = Cpanel_PublicAPI::getInstance($cpCfg);
    		$queryMF = array(
    			'module' => 'StatsBar',
    			'function' => 'stat',
    		);
    		$queryArgs = array(
    			'display' => 'diskusage|bandwidthusage'
    		);
    		$response = $cp->cpanel_api2_request('cpanel', $queryMF, $queryArgs);
    
    		echo '<pre>'.print_r($response, true).'</pre>';
    		...
    
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Using an access hash tends to be the preferred solution. It looks like you're using the public API here, correct?

    https://github.com/CpanelInc/cPanel-PublicAPI.git

    From first glance, the issue I see is that you're connecting to cPanel as the reseller with the access hash. The access hash only grants access over WHM, not cPanel. Therefore in this particular case, your only option is to use the password.

    You do also have the ability to make the API2 call over WHM instead, which iirc is supported in the Perl version of the public API.

    cPanel XML and JSON APIs
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Yes, you must use the password in the scenario you described. We don't support cPanel access with the root/reseller override using any other mechanism at this time.

    Thank you.
     
Loading...

Share This Page