API : Retrive customer info (php)

Hello I would like to retrieve customer information via the API.
I went to see the Apiary but without success (sorry i m beginner in such developpment)

I have an error: bool (false).

Do you have a complete example code in PHP with authentication ?

thanks a lot !!!

my code

<?php $api_key = 'XXXXXXXXXX'; $api_secret = 'XXXXXXXXXXXXXXX'; $nonce = round(microtime(true) * 100); $signature = strtoupper(hash_hmac('sha256', $nonce . $api_key, $api_secret)); $auth_data = array( 'key' => $api_key, 'signature' => $signature, 'nonce' => $nonce++ ); $auth_string = http_build_query($auth_data); $header = 'Authorization: Splynx-EA (' . $auth_string . ')'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://xxx.xxx.xx.xx/admin/customers/customer-info/id "); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); $response = curl_exec($ch); curl_close($ch); var_dump($response); ?>

First please add Splynx API key and add permission to view customers.
Then use something like this:

<?php
require '/var/www/splynx/addons/splynx-php-api/SplynxApi.php';

$api_url = 'https://example.com/'; // please set your Splynx URL. With last slash / !!!

$key = "XXXXXXXX"; // please set your key
$secret = "XXXXXXXX"; // please set your secret

// don't forget to add permissions to API Key, for changing locations.

$api = new SplynxAPI($api_url, $key, $secret);

print "Customers list:\n";

$result = $api->api_call_get("admin/customers/customer");
print "Result: ";
if ($result) {
    print "Ok!\n";
    print_r($api->response);
} else {
    print "Fail! Error code: $api->response_code\n";
    print_r($api->response);
}
print "\n-------------------------------------------------\n";

Also we have few useful examples here: https://splynx.com/wiki/?wikipage=API

thanks for your answer.
It works. i can now list customers info.

but still can’t update informations like name, status or city i have an error :slight_smile:

Result: Fail! Error code: 500

my code

$locationsApiUrl=“admin/customers/customer/11”;
$custumerid=11;
$params=array(‘name’ => ‘Gael GARAND stephan’,‘city’ => ‘Douala’);

print “Changer infos client\n”;

$result = $api->api_call_put($locationsApiUrl,$custumerid,array(‘name’ =>‘Gael GARAND stephan’,‘city’ => ‘Douala’));

print "Result: ";
if ($result) {
    print "Ok!\n";
    print_r($api->response);
} else {
    print "Fail! Error code: $api->response_code\n";
    print_r($api->response);

I wrote your code and received 404 error
I changed $locationsApiUrl to “admin/customers/customer” - received 403 error (API key don’t have permission)
Added permission under Administration / API keys / Permissions and it become work

Your code, fixed:

$locationsApiUrl="admin/customers/customer";
$custumerid=1;

print "Changer infos client\n";

$result = $api->api_call_put($locationsApiUrl,$custumerid,array('name' =>'Gael GARAND stephan','city' => 'Douala'));

print "Result: ";
if ($result) {
    print "Ok!\n";
    print_r($api->response);
} else {
    print "Fail! Error code: $api->response_code\n";
    print_r($api->response);
}

P.S.: You find useful information in nginx logs. Monitor them during API script work:

bash> tail -F /var/www/splynx/logs/nginx/splynx-error.log /var/www/splynx/logs/nginx/splynx-access.log

Thank you very much.
the permissions where already good
i changed the $locationApiUrl, removing the slash and the id like you said and its work.

thanks a lot.