Control Web Panel

WebPanel => Information => Topic started by: kiranuk on December 14, 2017, 04:55:17 AM

Title: Regarding API
Post by: kiranuk on December 14, 2017, 04:55:17 AM
Hi, I have one question regarding API, ( I have CWP-7)

In the CWP panel, Under Plugin->API Manager, I have configured API access & then
I have added remote IP address to this file  “/usr/local/cwp/.conf/api_allowed.conf”
Also I have added API key to this file “/usr/local/cwp/.conf/api_key.conf”
( as per the documentation in http://wiki.centos-webpanel.com/cwp-account-api)

If I click to any function in the API manager its showing like below.

Url:   https://myip:2304/v1/packages   Method:   POST   Actions:   add, udp, del, list   Return:   JSON / XML

My question is how can call API function using curl method in the termianl. Can you please show me one example OR documentation link for the same.

If I do like this in the termianl its not working
# curl https://myip:2304/v1/packages

Please give me one clear example to perform API request in the termianl.

Regards
kiran upadhya
Title: Re: Regarding API
Post by: Netino on December 20, 2017, 12:31:34 AM
CWP-7..?? are you meaning Centos7..??

Try:
curl -k https://myip:2304/v1/packages -d key=blablablablabla -d action=list

The -k parameter is to curl not to claim about selfsigned certificates.
The parameter -d is to pass parameters via POST method.

The problem is I'm trying like you, but no answer.
Searching for ports with 'netstat', I just find port 2302, not 2304.
But likewise, trying with port 2302 doesn't work too.
Title: Re: Regarding API
Post by: Netino on December 20, 2017, 01:21:41 AM
If you do:
# cat /ADMINUSERNAME/.conf/apikey
ShortName|@|127.0.0.1|@|blablablablablablablablablablalblablalblabla|@|accout_add,accout_upd,accout_del,accout_list,accout_susp,accout_unsp,pack_add,pack_udp,pack_del,pack_list,emailadmin_list,changepack_udp,mysqlbd_add,mysqlbd_del,mysqlbd_list,mysqlbd_susp,mysqlb_unsp,mysqluser_add,mysqluser_del,mysqluser_list,typeserver_list,detailaccount_list,accountquo_list,cronuser_add,cronuser_del,cronuser_list,quotalimt_list,changpass_udp,|@|JSON|@|1

You can note there are several api names, old style.

So, you can try:
curl -k https://myip:PORT/api/ -d api=accout_list -d key=blablablablabla

Using PORTs 2031 and 2087, I get the answer:
Failed to include API File!!!

No solution, still.
Title: Re: Regarding API
Post by: josemnunez on December 21, 2017, 01:24:20 PM
Try this way in PHP


$data = array("key" => "MYKEY","action"=>'list');
$url = "https://IPSERVERAPI:2304/v1/packages";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt ($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
curl_close($ch);
echo $response; die;
Title: Re: Regarding API
Post by: Netino on January 03, 2018, 03:15:02 AM
It worked.

The solution is very simple, just execute the command:
sh /scripts/install_api

Regards,
Netino