Migrated from Redmine #284 | Author: Ahmed Hassan
Status: New | Priority: Normal | Created: 2018-11-14
Hello,
My developer is asking me for “API URL to send JsonRPC requests as well since that is not https://user-api.simplybook.me/login/”
Migrated from Redmine #284 | Author: Ahmed Hassan
Status: New | Priority: Normal | Created: 2018-11-14
Hello,
My developer is asking me for “API URL to send JsonRPC requests as well since that is not https://user-api.simplybook.me/login/”
Redmine Admin wrote:
What is your booking page url?
Ahmed Hassan wrote:
Redmine Admin wrote:
Please use https://user-api.simplybook.it/login/
Ahmed Hassan wrote:
Hi, my developer is asking how do we add client with your API.
Here is the code I was trying
$loginClient = new JsonRpcClient(‘https://user-api.simplybook.me’ . ‘/login/’);
$token = $loginClient->getToken(‘pathtoarabiccom’, ‘babdb8e53e8f8084a178fec1ecb4f78b0b0bb090b06cbc590d2fa6cc5936c8b3’);
$client = new JsonRpcClient(‘https://user-api.simplybook.me’ . ‘/admin/’, array(
‘headers’ => array(
'X-Company-Login: ’ . ‘pathtoarabiccom’,
'X-User-Token: ’ . $token
)
));
$res = $client->addClient(array(
‘name’ => ‘test one’,
‘email’ => ‘test1@gmail.com’,
));
var_dump($res);
and error is Fatal error: Uncaught JsonRpcFault: JSON cannot be decoded in C:\amembersvn\test.php:47 Stack trace: #0 C:\amembersvn\test.php(76): JsonRpcClient->__call(‘addClient’, Array) #1 {main} thrown in C:\amembersvn\test.php on line 47
Redmine Admin wrote:
Exception is error on your side, we can’t know what it is.
Ahmed Hassan wrote:
Well, the problem is that we are not getting any response for addClient request. IS that expected?
Most of all above code is from your API docs.
Do we do something wrong?
Redmine Admin wrote:
i see phone number is missing at least
Ahmed Hassan wrote:
So NULL as a response is expected?
Even if I send
'name' => 'test one',
'email' => 'test1@gmail.com',
'phone' => '+18005555555',
'address1' => "3872 Earnhardt Drive",
'address2' => "Louisville, KY 40219",
'city' => 'Louisville',
'zip' => '3872'
I get no response.
If I send $client->getCompanyParam(‘require_fields’); I get no response.
Ahmed Hassan wrote:
So NULL as a response is expected?
Even if I send
‘name’ => ‘test one’,
‘email’ => ‘test1@gmail.com’,
‘phone’ => ‘+18005555555’,
‘address1’ => “3872 Earnhardt Drive”,
‘address2’ => “Louisville, KY 40219”,
‘city’ => ‘Louisville’,
‘zip’ => ‘3872’
I get no response.
If I send $client->getCompanyParam(‘require_fields’); I get no response.
Redmine Admin wrote:
Please try to use https://user-api.simplybook.it API endpoint and check if you can get auth token
Ahmed Hassan wrote:
Token is working fine.
The question is about “addClient” API method.
How do we send that request?
Ahmed Hassan wrote:
Token is working fine.
The question is about “addClient” API method.
How do we send that request?
Redmine Admin wrote:
we got " Uncaught exception ‘Exception’ with message ‘Request error: Client password is not valid’"
<?php
require_once 'JsonRpcClient.php';
try {
$loginClient = new JsonRpcClient('https://user-api.simplybook.it' . '/login/');
$token = $loginClient->getToken('pathtoarabiccom', 'HIDDDDENNNN');
$client = new JsonRpcClient('https://user-api.simplybook.it' . '/', array(
'headers' => array(
'X-Company-Login: ' . 'pathtoarabiccom',
'X-Token: ' . $token
)
));
} catch (Exception $e) {
$serviceEnabled = false;
var_dump($e);
exit();
}
$res = $client->addClient(array(
'name' => 'API dev test 1',
'email' => 'test-email@test.com',
'phone' => '1234567890',
'password' => '123456',
));
var_dump($res);
?>
result
object(stdClass)#4 (13) {
["id"]=>
string(1) "8"
["email"]=>
string(19) "test-email@test.com"
["pass"]=>
string(32) "081f4543cbd0f758b81027e513477c1b"
["name"]=>
string(14) "API dev test 1"
["phone"]=>
string(11) "+1234567890"
["is_blocked"]=>
string(1) "0"
["address1"]=>
NULL
["address2"]=>
NULL
["city"]=>
NULL
["zip"]=>
NULL
["country_id"]=>
NULL
["state_id"]=>
NULL
["client_hash"]=>
string(32) "c04332c28f6fdf5b5f38d7cc29740de5"
}
Ahmed Hassan wrote:
Could you please provide your version of JsonRpcClient.php as well?
Ahmed Hassan wrote:
Could you please provide your version of JsonRpcClient.php as well?
Redmine Admin wrote:
<?php
/**
* JSON-RPC CLient class
*/
class JsonRpcClient {
protected $_requestId = 1;
protected $_contextOptions;
protected $_url;
/**
* Constructor. Takes the connection parameters
*
* @param String $url
*/
public function __construct($url, $options = array()) {
$headers = array('Content-type: application/json');
if (isset($options['headers'])) {
$headers = array_merge($headers, $options['headers']);
}
$this->_contextOptions = array(
'http' => array(
'method' => 'POST',
'header' => implode("\r\n", $headers) . "\r\n"
)
);
$this->_url = $url;
}
/**
* Performs a jsonRCP request and return result
*
* @param String $method
* @param Array $params
* @return mixed
*/
public function __call($method, $params) {
$currentId = $this->_requestId++;
$request = array(
'method' => $method,
'params' => array_values($params),
'id' => $currentId
);
$request = json_encode($request);
$this->_contextOptions['http']['content'] = $request;
$response = file_get_contents($this->_url, false, stream_context_create($this->_contextOptions));
//var_dump($response);
$result = json_decode($response, false);
if ($result->id != $currentId) {
//echo $response;
throw new Exception("Incorrect response id (request id: {$currentId}, response id: {$result->id})" . "\n\nResponse: " . $response);
}
if (isset($result->error) && $result->error) {
throw new Exception("Request error: {$result->error->message}");
}
return $result->result;
}
}
Ahmed Hassan wrote:
Thanks!
(Short original content)