API Dokümantasyonu

REST API endpoints ve örnekler

Genel Bakış

MarkaClick, geliştiriciler için kapsamlı bir REST API sunar. Bu API ile ürün, sipariş, müşteri ve envanter verilerine programatik erişim sağlayabilirsiniz.

API Sürümü

Mevcut API sürümü: v1
Tüm endpoint'ler /api/v1/ prefix'i ile başlar.

Kimlik Doğrulama

API istekleri Bearer Token veya API Key ile doğrulanır.

API Key Alma

  1. Admin Panel'e giriş yapın
  2. Ayarlar > API bölümüne gidin
  3. "Yeni API Key Oluştur" butonuna tıklayın
  4. Key'i güvenli bir yerde saklayın

Header ile Doğrulama

# Bearer Token
curl -X GET "https://site.com/api/v1/products" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Alternatif: X-API-Key Header
curl -X GET "https://site.com/api/v1/products" \
  -H "X-API-Key: YOUR_API_KEY"

Response Formatı

Tüm API yanıtları JSON formatındadır:

Başarılı Yanıt

{
    "success": true,
    "data": {
        "id": 123,
        "name": "Ürün Adı",
        "price": 99.90
    },
    "meta": {
        "total": 1,
        "page": 1,
        "per_page": 20
    }
}

Hata Yanıtı

{
    "success": false,
    "error": {
        "code": "VALIDATION_ERROR",
        "message": "Ürün adı zorunludur",
        "field": "name"
    }
}

HTTP Durum Kodları

Kod Durum Açıklama
200 OK İstek başarılı
201 Created Kayıt oluşturuldu
400 Bad Request Geçersiz istek parametreleri
401 Unauthorized Geçersiz veya eksik API key
404 Not Found Kayıt bulunamadı
429 Too Many Requests Rate limit aşıldı
500 Server Error Sunucu hatası

Ürünler API

Ürün Listesi

GET /api/v1/products

Query Parametreleri:

Parametre Tip Açıklama
page integer Sayfa numarası (varsayılan: 1)
per_page integer Sayfa başına kayıt (max: 100)
category_id integer Kategori filtresi
search string Ürün adında arama
status string active, inactive, all

Tekil Ürün

GET /api/v1/products/{id}

Ürün Oluştur

POST /api/v1/products
{
    "name": "Yeni Ürün",
    "slug": "yeni-urun",
    "price": 199.90,
    "sale_price": 149.90,
    "category_id": 5,
    "description": "Ürün açıklaması...",
    "stock": 100,
    "status": "active"
}

Ürün Güncelle

PUT /api/v1/products/{id}

Ürün Sil

DELETE /api/v1/products/{id}

Siparişler API

Sipariş Listesi

GET /api/v1/orders

Sipariş Detayı

GET /api/v1/orders/{id}

Sipariş Durumu Güncelle

PATCH /api/v1/orders/{id}/status
{
    "status": "shipped",
    "tracking_number": "1234567890",
    "carrier": "aras"
}

Müşteriler API

Müşteri Listesi

GET /api/v1/customers

Müşteri Detayı

GET /api/v1/customers/{id}

Rate Limiting

API istekleri rate limit ile korunur:

100
İstek / Dakika
5,000
İstek / Saat
50,000
İstek / Gün

Rate limit bilgileri response header'larında döner:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640000000

Webhooks

Belirli olaylarda otomatik HTTP bildirimi almak için webhook tanımlayabilirsiniz.

Desteklenen Olaylar

  • order.created - Yeni sipariş oluşturulduğunda
  • order.updated - Sipariş güncellendiğinde
  • order.completed - Sipariş tamamlandığında
  • product.created - Yeni ürün eklendiğinde
  • product.updated - Ürün güncellendiğinde
  • stock.low - Stok düşük seviyeye geldiğinde

Webhook Payload Örneği

{
    "event": "order.created",
    "timestamp": "2024-01-15T10:30:00Z",
    "data": {
        "order_id": 12345,
        "total": 299.90,
        "status": "pending",
        "customer": {
            "id": 789,
            "email": "musteri@email.com"
        }
    },
    "signature": "sha256=abc123..."
}

SDK ve Örnekler

Farklı diller için SDK ve örnek kodlar:

PHP Örneği

<?php
$apiKey = 'your_api_key';
$baseUrl = 'https://site.com/api/v1';

// Ürün listesini al
$ch = curl_init("$baseUrl/products");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer $apiKey",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$products = json_decode($response, true);

print_r($products);

JavaScript Örneği

const API_KEY = 'your_api_key';
const BASE_URL = 'https://site.com/api/v1';

// Ürün listesini al
fetch(`${BASE_URL}/products`, {
    headers: {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json'
    }
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));