Author Topic: Error API 404  (Read 595 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Error API 404
« on: January 05, 2024, 07:34:33 PM »
When I make a post using curl the API returns a 404 error page to me.

I'm trying to list all cwp accounts but only the error is returned, checking the logs in /usr/local/cwpsrv/logs/2304_error_log it shows me the following

Quote
2024/01/05 16:31:01 [notice] 79020#0: *7119 "^/v1/([^/]+)/?$" matches "/v1/account", client: my_ip, server: localhost, request: "POST /v1/account?key=my_key&action=list HTTP/1.1", host: "my_server_ip:2304"
2024/01/05 16:31:01 [notice] 79020#0: *7119 rewritten data: "/v1/index.php", args: "method=", client: my_ip, server: localhost, request: "POST /v1/account?key=my_key&action=list HTTP/1.1", host: "my_server_ip:2304"
2024/01/05 16:31:01 [info] 79020#0: *7119 client my_ip closed keepalive connection

Can anyone shed some light on what this problem could be?
I am using the following command to get the information

Quote
curl -k -X POST "https://my_server_ip:2304/v1/account?key=my_key&action=list"

Offline
****
Re: Error API 404
« Reply #1 on: January 06, 2024, 12:52:47 AM »
You're using GET variables with a POST command.  The PHP example clearly shows how to do this.
Code: [Select]
Example in PHP:

$data = array("key" => "MYKEY","action"=>'list');
$url = "https://IPSERVERAPI:2304/v1/account";
$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);

For the command line
curl -k -X POST -d "key=my_key&action=list" "https://my_server_ip:2304/v1/account"
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: Error API 404
« Reply #2 on: January 08, 2024, 05:48:17 PM »
Thanks for your help in solving this problem!

You're using GET variables with a POST command.  The PHP example clearly shows how to do this.
Code: [Select]
Example in PHP:

$data = array("key" => "MYKEY","action"=>'list');
$url = "https://IPSERVERAPI:2304/v1/account";
$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);

For the command line
curl -k -X POST -d "key=my_key&action=list" "https://my_server_ip:2304/v1/account"