บทความเกี่ยวกับ: BentoWeb API

PHP Example การดึงข้อมูล Product List [Get method]

การดึงข้อมูลรายการสินค้า (Get Product List)

1. PHP Request Code

PHP

<?php

$accessToken = '[Access Token]';
$storeId = [Store ID];

$params = [
'store_id' => $storeId,
// 'page' => 1, // (Optional) หน้าที่ต้องการดึงข้อมูล
// 'limit' => 20, // (Optional) จำนวนรายการต่อหน้า
];

$url = "https://queue.bentoweb.com/api/productlist?" . http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$result = json_decode($response); // แปลง JSON เป็น Object
curl_close($ch);

// แสดงผลลัพธ์
// print_r($result);
?>

2. ตัวอย่างค่าที่ได้รับ (JSON Response)

JSON

{
"data": {
"total": 138,
"product_list": [
{
"product_id": 46506,
"store_id": 12345,
"name": "Zero Item",
"description": "",
"seo_url": "product-46506",
"price": 300,
"label": "",
"weight": 0,
"override_loyalty": false,
"loyalty_points": 0,
"remain_stock": 960,
"seq": 11,
"active": false,
"thumb": "https://image-url...",
"image": "https://image-url...",
"category": [],
"product_variant": [
{
"product_variant_id": 71963,
"product_id": 46506,
"name": "ธรรมดา",
"sku": "abc-286",
"barcode": "BTW0000000071963",
"price": 600,
"has_wholesale": true,
"wholesale": {},
"override_loyalty": false,
"loyalty_points": 0,
"seq": 1,
"default": true,
"stock": 995,
"pre_sold": 12,
"post_sold": 23,
"real_stock": 960,
"customer_group_name": ""
}
]
}
]
},
"status": 1
}

คำอธิบายเพิ่มเติม:

  • real_stock: คือจำนวนสินค้าคงเหลือที่ขายได้จริง (คำนวณจาก stock - pre_sold - post_sold)
  • product_variant: อาร์เรย์เก็บข้อมูลตัวเลือกสินค้า
  • status: ค่า 1 หมายถึงการร้องขอสำเร็จ

อัปเดตเมื่อ: 30/01/2026

บทความนี้เป็นประโยชน์หรือไม่?

แบ่งปันความคิดเห็นของคุณ

ยกเลิก

ขอบคุณ!