PHP Örnekleri
PHP ile KolayBi API'sini kullanma örnekleri.
🔐 Yetkilendirme
Access Token Alma
function getAccessToken($apiKey, $channel) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/access_token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Channel: ' . $channel,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['api_key' => $apiKey]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
return $data['data'];
}
👥 Cari Hesap İşlemleri
Müşteri Listeleme
function listAssociates($accessToken, $channel) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/associates');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,
'Channel: ' . $channel
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
Müşteri Oluşturma
function createAssociate($accessToken, $channel, $associateData) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/associates');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,
'Channel: ' . $channel,
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($associateData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
📦 Ürün İşlemleri
Ürün Listeleme
function listProducts($accessToken, $channel) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/products');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,
'Channel: ' . $channel
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
🧾 Fatura İşlemleri
Fatura Listeleme
function listInvoices($accessToken, $channel) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/invoices');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken,
'Channel: ' . $channel
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}