Ürün Görseli Yükle
Bir ürün görseli yükler. İlk görsel otomatik olarak kapak olur. Desteklenen formatlar: JPG, PNG, WEBP (en fazla 5 MB).
URL Parametreleri
| Parametre | Tip | Açıklama |
|---|---|---|
id | integer | Ürün ID |
Yükleme Yöntemleri
| Yöntem | Nasıl |
|---|---|
| Multipart dosya (önerilen) | Form alanı image |
| Uzak URL | JSON {"image_url":"https://..."} |
| Base64 | JSON {"image_base64":"data:image/jpeg;base64,..."} |
PHP
<?php
$baseUrl = 'https://example.com/api/v1';
$apiKey = 'YOUR_API_KEY';
$productId = 6;
function apiRequest(string $method, string $url, string $apiKey, ?array $data = null): array
{
$ch = curl_init();
$headers = [
'X-API-Key: ' . trim($apiKey),
'Accept: application/json',
];
if ($data !== null) {
$headers[] = 'Content-Type: application/json';
}
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => true,
]);
if ($data !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
}
$response = curl_exec($ch);
$httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
$decoded = json_decode((string) $response, true);
return [
'http_code' => $httpCode,
'curl_error' => $error,
'response' => is_array($decoded) ? $decoded : $response,
];
}
function apiUploadImage(string $url, string $apiKey, string $filePath): array
{
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . trim($apiKey),
'Accept: application/json',
],
CURLOPT_POSTFIELDS => [
'image' => new CURLFile(
$filePath,
mime_content_type($filePath) ?: 'image/jpeg',
basename($filePath)
),
],
CURLOPT_SSL_VERIFYPEER => true,
]);
$response = curl_exec($ch);
$httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
$decoded = json_decode((string) $response, true);
return [
'http_code' => $httpCode,
'curl_error' => $error,
'response' => is_array($decoded) ? $decoded : $response,
];
}
// Option A — local file
$result = apiUploadImage(
$baseUrl . '/products/' . $productId . '/image',
$apiKey,
__DIR__ . '/sample-product.jpg'
);
// Option B — remote URL
// $result = apiRequest('POST', $baseUrl . '/products/' . $productId . '/image', $apiKey, [
// 'image_url' => 'https://example.com/urun.jpg',
// ]);
print_r($result);
cURL
# Multipart file upload
curl -s -X POST \
-H "X-API-Key: YOUR_API_KEY" \
-H "Accept: application/json" \
-F "image=@C:/path/urun.jpg" \
"https://example.com/api/v1/products/6/image"
# From remote URL
curl -s -X POST \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image_url":"https://example.com/urun.jpg"}' \
"https://example.com/api/v1/products/6/image"
Örnek Yanıt (JSON)
{
"success": true,
"message": "Image uploaded",
"data": {
"id": 12,
"product_id": 6,
"url": "https://example.com/img/products/12.jpg"
}
}