|
|||
|
API2 Basics?
I've had a little experience coding with the old cPanel Accounting Module in PHP, but I'd like to start using the new API2.
I've browsed through the docs at http://www.cpanel.net/plugins/api2/index.html But I can't find anything that spells out how to actually use the API2 Tags in a real-world situation. Can anyone point me in the right direction? |
|
|||
|
Looking through the forums it appears that I'm not the first person to ask this question.
So I'll try to work this out and post my results here for the benefit of everyone who has asked. The first things I've noticed are. 1) Be careful of what you find via Google searches because most of it deals with the old cPanel Accounting module. 2) The secret to using the cPanel API2 tags in PHP seems to be Curl. I'll try and post some sample code when I work out how to do it. |
|
|||
|
I'm getting nowhere fast. I've gathered a few cryptic clues from varous forum posts but I can find no clear explanation of how to implement the API in an actual script.
I think https://user ass@server:2086/xml-api/applist should return all available XML API functions from the cPanel server, but it doesn't return anything for me.Can anyone give me a couple more clues as to how to do this? |
|
||||
|
Quote:
Try logging into WHM and then going to https://server:2087/xml-api/applist or http://server:2086/xml-api/applist Do you see any XML output now?
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
|
|||
|
Quote:
I was trying to run it from another server, not the server itself. If I log into WHM and paste the link into the address bar, I can get it to return the app list, but it prompts me to log in again. What I really want to do is access the details of remote servers, not the local one- is there a way to do this? Last edited by mikelegg; 12-18-2008 at 04:42 PM. |
|
||||
|
Quote:
PHP Code:
You will need reseller access or better on those remote servers to be able to use the APIs on those servers. Also note, you can't do anything via the API that you wouldn't be able to do via the WHM interface with the same credentials.
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
|
|||
|
One more question ... what syntax is used to specify an API2 path?
I've used /xml-api/listaccts to build an array of domains, now I'd like to use Email::listmaildomains to get all parked and addon domains that have mail addresses on the account. The sample code in the documentation is ... <?cp Email::listmaildomains( %, domain) skipmain=1 ?> But obviously that syntax won't work in PHP. I think it's something like'/xml-api/cpanel?listmaildomains&domain='. $domain .'&skipmain=1', but that's not working for me at present. I've also tried '/xml-api/cpanel?user=root&xmlin=<cpanelaction><module>Email </module><apiversion>2</apiversion><func>listmaildomains</func><args><domain>'. $domain .'</domain></args></cpanelaction>' But it doesn't return anything. Last edited by mikelegg; 12-18-2008 at 11:39 PM. |
|
||||
|
The space after Email in:
Code:
...<cpanelaction><module>Email </module>...
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
|
|||
|
Quote:
If I edit the post it doesn't appear, so I can't remove it. |
|
||||
|
What's your full cPanel/WHM version information?
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
|
||||
|
Okay.
You mention that nothing is being returned. So if not even an error message is being returned, are you sure the connection to the server is properly established?
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
|
|||
|
Quote:
Then I'm looping through the array of domains and executing /xml-api/cpanel?user=titan&xmlin=<cpanelaction><module>Emai l</module><apiversion>2</apiversion><func>listmaildomains</func><args><domain>'. $domain .'</domain></args></cpanelaction> for each domain in the array. It's only this second call that's not returning anything. I've assumed there are accounts on the server that have email addresses on secondary domains - but maybe I've assumed wrong? |
|
||||
|
Quote:
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit |
![]() |
| Thread Tools | |
| Display Modes | |
|
|