Stok Hareketi Oluşturma
Ürün stok hareketlerini yönetme.
Endpoint
POST /kolaybi/v1/stock_histories
Parametreler
Parametre | Tip | Zorunlu | Açıklama |
---|---|---|---|
product_id | integer | Evet | Ürün ID |
quantity | number | Evet | Miktar |
stock_flow_direction | integer | Evet | Yön (1: giriş, -1: çıkış) |
description | string | Hayır | Stok hareketi açıklaması |
unit_amount | number | Hayır | Birim fiyat |
currency | string | Hayır | Para birimi |
issue_date | string | Hayır | Hareket tarihi |
Örnekler
- cURL
- JavaScript
- PHP
- Python
- C#
# Temel stok girişi
curl -X POST "https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Channel: YOUR_CHANNEL" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "product_id=1&quantity=10&stock_flow_direction=1"
# Detaylı stok çıkışı
curl -X POST "https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Channel: YOUR_CHANNEL" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "product_id=1&quantity=5&stock_flow_direction=-1&description=Satış için çıkış&unit_amount=100.00¤cy=TRY&issue_date=2024-01-15"
async function createStockHistory(data) {
const formData = new URLSearchParams(data);
const response = await fetch(
"https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories",
{
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
Channel: channel,
"Content-Type": "application/x-www-form-urlencoded",
},
body: formData,
}
);
return await response.json();
}
// Temel kullanım - Stok girişi
const stockIn = await createStockHistory({
product_id: 1,
quantity: 10,
stock_flow_direction: 1,
});
// Detaylı kullanım - Stok çıkışı
const stockOut = await createStockHistory({
product_id: 1,
quantity: 5,
stock_flow_direction: -1,
description: "Satış için çıkış",
unit_amount: 100.0,
currency: "TRY",
issue_date: "2024-01-15",
});
function createStockHistory($data) {
$url = 'https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $accessToken,
'Channel: ' . $channel,
'Content-Type: application/x-www-form-urlencoded'
],
CURLOPT_RETURNTRANSFER => true
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Temel kullanım - Stok girişi
$stockIn = createStockHistory([
'product_id' => 1,
'quantity' => 10,
'stock_flow_direction' => 1
]);
// Detaylı kullanım - Stok çıkışı
$stockOut = createStockHistory([
'product_id' => 1,
'quantity' => 5,
'stock_flow_direction' => -1,
'description' => 'Satış için çıkış',
'unit_amount' => 100.00,
'currency' => 'TRY',
'issue_date' => '2024-01-15'
]);
import requests
def create_stock_history(data):
url = "https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories"
headers = {
"Authorization": f"Bearer {access_token}",
"Channel": channel,
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, headers=headers, data=data)
return response.json()
# Temel kullanım - Stok girişi
stock_in = create_stock_history({
"product_id": 1,
"quantity": 10,
"stock_flow_direction": 1
})
# Detaylı kullanım - Stok çıkışı
stock_out = create_stock_history({
"product_id": 1,
"quantity": 5,
"stock_flow_direction": -1,
"description": "Satış için çıkış",
"unit_amount": 100.00,
"currency": "TRY",
"issue_date": "2024-01-15"
})
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
async Task<dynamic> CreateStockHistoryAsync(Dictionary<string, string> data)
{
using var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post,
"https://ofis-sandbox-api.kolaybi.com/kolaybi/v1/stock_histories")
{
Content = new FormUrlEncodedContent(data)
};
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("Channel", channel);
var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<dynamic>(content);
}
// Temel kullanım - Stok girişi
var stockIn = await CreateStockHistoryAsync(new Dictionary<string, string>
{
{ "product_id", "1" },
{ "quantity", "10" },
{ "stock_flow_direction", "1" }
});
// Detaylı kullanım - Stok çıkışı
var stockOut = await CreateStockHistoryAsync(new Dictionary<string, string>
{
{ "product_id", "1" },
{ "quantity", "5" },
{ "stock_flow_direction", "-1" },
{ "description", "Satış için çıkış" },
{ "unit_amount", "100.00" },
{ "currency", "TRY" },
{ "issue_date", "2024-01-15" }
});
Yanıt Formatı
{
"success": true,
"data": {
"id": 1,
"product_id": 1,
"quantity": 10,
"stock_flow_direction": 1,
"description": "Stok girişi",
"unit_amount": 100.0,
"currency": "TRY",
"issue_date": "2024-01-15",
"created_at": "2024-01-15T10:30:00Z"
}
}
Yanıt Alanları
Alan | Tip | Açıklama |
---|---|---|
id | integer | Stok hareketi ID |
product_id | integer | Ürün ID |
quantity | number | Miktar |
stock_flow_direction | integer | Yön (1: giriş, -1: çıkış) |
description | string | Hareket açıklaması |
unit_amount | number | Birim fiyat |
currency | string | Para birimi |
issue_date | string | Hareket tarihi |
created_at | string | Oluşturulma tarihi |
Kurallar
Önemli
- Ürün ID: Sistemde mevcut olmalı
- Miktar: Pozitif değer olmalı
- Yön: 1 (giriş) veya -1 (çıkış) olmalı
- Stok kontrolü: Çıkış için yeterli stok olmalı
- Tarih formatı: YYYY-MM-DD olmalı