Hashtopolis Forum
How to use User API? - Printable Version

+- Hashtopolis Forum (https://hashtopolis.org)
+-- Forum: Support (https://hashtopolis.org/forum-1.html)
+--- Forum: Howto (https://hashtopolis.org/forum-5.html)
+--- Thread: How to use User API? (/thread-936.html)

How to use User API? - raptork - 10-09-2020

I am curious how to use the User API.

The first question is what is the URL of the User API. Is it /api/user.php ?

I try to test the functionality with GET and POST request, but the response is the same: 

{"section":"INV","request":"INV","response":"ERROR","message":"Invalid user api query!"}

The GET request is: 


which I refer to the documentation at: https://github.com/s3inlc/hashtopolis/blob/master/doc/user-api/user-api.pdf

The POST request is similar, which I call it via PHP:

header('Content-Type: text/plain');

$data = array(
"section" => "test",
"request" => "connection"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://example.com/hashtopolis/api/user.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Possible attack hole: Man In The Middle
$response = curl_exec($ch);


Identical response via POST. So what did I miss?

RE: How to use User API? - s3in!c - 10-09-2020

The request data should be sent via POST and being in json format, so the header should be set accordingly (not necessary, but to be correct) and the data needs to be encoded with json_encode() before sending.
The automatic CI tests done on the API should help you if in doubt: https://github.com/s3inlc/hashtopolis/blob/master/ci/HashtopolisTestFramework.class.php#L65

RE: How to use User API? - raptork - 10-12-2020

It works. Thanks for the tip!