Author Topic: Regarding API  (Read 11253 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Regarding API
« 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

Offline
***
Re: Regarding API
« Reply #1 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.
« Last Edit: December 20, 2017, 01:11:55 AM by Netino »

Offline
***
Re: Regarding API
« Reply #2 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.

Offline
*****
Re: Regarding API
« Reply #3 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;

Offline
***
Re: Regarding API
« Reply #4 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