Authenticating with access hash instead of reseller password with cPanel API2

devel

Member
Sep 21, 2013
5
0
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>';
		...
 

vanessa

Well-Known Member
PartnerNOC
Sep 26, 2006
833
28
178
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
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,202
363
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.