SDK JavaScript / Node.js
Classe wrapper utilisant fetch. Compatible navigateur et Node.js 18+.
class SalonHubClient {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseURL = 'https://api.salonhub.app/api';
}
async request(method, path, data = null) {
const options = {
method,
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json',
},
};
if (data) options.body = JSON.stringify(data);
const res = await fetch(this.baseURL + path, options);
const json = await res.json();
if (!res.ok) throw new Error(json.error || 'API Error');
return json;
}
// Clients
getClients(params = {}) {
return this.request('GET', '/clients?' + new URLSearchParams(params));
}
getClient(id) { return this.request('GET', `/clients/${id}`); }
createClient(data) { return this.request('POST', '/clients', data); }
updateClient(id, data) { return this.request('PUT', `/clients/${id}`, data); }
deleteClient(id) { return this.request('DELETE', `/clients/${id}`); }
// Services
getServices(params = {}) { return this.request('GET', '/services?' + new URLSearchParams(params)); }
createService(data) { return this.request('POST', '/services', data); }
// Appointments
getAppointments(params = {}) {
return this.request('GET', '/appointments?' + new URLSearchParams(params));
}
createAppointment(data) { return this.request('POST', '/appointments', data); }
updateStatus(id, status) {
return this.request('PATCH', `/appointments/${id}/status`, { status });
}
}
// Utilisation
const client = new SalonHubClient('sk_live_votre_cle_api');
// Lister les clients
const { data } = await client.getClients({ search: 'Marie' });
// Creer un rendez-vous
await client.createAppointment({
client_id: 1,
service_id: 3,
appointment_date: '2025-04-15',
start_time: '10:00',
end_time: '11:00',
});
SDK PHP
Classe wrapper utilisant cURL. Compatible PHP 7.4+.
<?php
class SalonHubClient {
private $apiKey;
private $baseURL = 'https://api.salonhub.app/api';
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
private function request($method, $path, $data = null) {
$ch = curl_init($this->baseURL . $path);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $this->apiKey,
'Content-Type: application/json',
],
]);
if ($data) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode >= 400) {
throw new Exception($result['error'] ?? 'API Error');
}
return $result;
}
// Clients
public function getClients($params = []) {
return $this->request('GET', '/clients?' . http_build_query($params));
}
public function createClient($data) {
return $this->request('POST', '/clients', $data);
}
// Appointments
public function getAppointments($params = []) {
return $this->request('GET', '/appointments?' . http_build_query($params));
}
public function createAppointment($data) {
return $this->request('POST', '/appointments', $data);
}
}
// Utilisation
$client = new SalonHubClient('sk_live_votre_cle_api');
$clients = $client->getClients(['search' => 'Marie']);
print_r($clients['data']);
SDK Python
Classe wrapper utilisant requests. Compatible Python 3.7+.
import requests
class SalonHubClient:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://api.salonhub.app/api'
self.headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
def _request(self, method, path, data=None, params=None):
r = requests.request(
method,
self.base_url + path,
headers=self.headers,
json=data,
params=params,
)
r.raise_for_status()
return r.json()
# Clients
def get_clients(self, **params):
return self._request('GET', '/clients', params=params)
def create_client(self, data):
return self._request('POST', '/clients', data=data)
# Services
def get_services(self, **params):
return self._request('GET', '/services', params=params)
# Appointments
def get_appointments(self, **params):
return self._request('GET', '/appointments', params=params)
def create_appointment(self, data):
return self._request('POST', '/appointments', data=data)
def update_status(self, appointment_id, status):
return self._request(
'PATCH',
f'/appointments/{appointment_id}/status',
data={'status': status},
)
# Utilisation
client = SalonHubClient('sk_live_votre_cle_api')
# Lister les clients
result = client.get_clients(search='Marie')
for c in result['data']:
print(f"{c['first_name']} {c['last_name']}")
# Creer un rendez-vous
client.create_appointment({
'client_id': 1,
'service_id': 3,
'appointment_date': '2025-04-15',
'start_time': '10:00',
'end_time': '11:00',
})
cURL
Exemples bruts utilisables directement dans le terminal.
Authentification
curl -X POST https://api.salonhub.app/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"marie@monsalon.fr","password":"motdepasse123"}'
Lister les clients
curl https://api.salonhub.app/api/clients \
-H "Authorization: Bearer sk_live_votre_cle_api"
Creer un rendez-vous
curl -X POST https://api.salonhub.app/api/appointments \
-H "Authorization: Bearer sk_live_votre_cle_api" \
-H "Content-Type: application/json" \
-d '{
"client_id": 1,
"service_id": 3,
"appointment_date": "2025-04-15",
"start_time": "10:00",
"end_time": "11:00"
}'
Changer le statut
curl -X PATCH https://api.salonhub.app/api/appointments/42/status \
-H "Authorization: Bearer sk_live_votre_cle_api" \
-H "Content-Type: application/json" \
-d '{"status":"confirmed"}'
Gestion des erreurs
{
"success": false,
"error": "Cle API invalide",
"message": "Cette cle API n'existe pas ou a ete desactivee"
}