การเรียกดูข้อมูลสินค้า
เนื้อหานี้สำหรับการใช้งาน New Product API ผ่าน /product-masters
เท่านั้น
การเรียกดูแบบระบุ Id ของสินค้า
สามารถระบุ product master id ของสินค้าที่ต้องการได้ด้วยการส่ง Get request ไปยัง /product-masters/:id
โดย id จะเป็นค่าเดียวกันกับ id ที่ปรากฏท้าย URL ในหน้าจอรายละเอียดของสินค้าบน FlowAccount
การเรียกดูแบบหลายรายการและการค้นหาสินค้า
สามารถเรียกดูรายการสินค้าได้ด้วยการส่ง Get request ไปยัง /product-masters
ซึ่งผลลัพธ์ที่ได้จะเป็นรายการแบบ paginated
เริ่มต้นที่ 20 รายการต่อ 1 page ซึ่งสามารถระบุขนาดที่ต้องการได้ ด้วยการส่ง pageSize
ที่มีค่าระหว่าง 1 และ 250
กรณีที่ระบุไว้เกินกว่าที่กำหนด API จะปรับให้เหลือ 250 ทันที ส่วนการระบุ page ที่ต้องการแสดงบน
ให้ส่ง currentPage
มาใน query parameter หากไม่ระบุ จะมีค่าเริ่มเป็น 1
ทั้งนี้ response data ของการเรียกดูแบบหลายรายการ จะอยู่ในรูปแบบดังนี้
Field | Type | Description |
---|---|---|
total | number | จำนวน product master ที่มีภายใต้ธุรกิจนั้น ๆ |
currentPage | number | ลำดับของ page ที่แสดงผลลัพธ์ปัจจุบัน |
list | ProductMasterSummary[] | Array ของ product master summary โดยจำนวน element จะเท่ากับ pageSize ที่ request แต่จะน้อยกว่าสำหรับรายการที่เหลือ |
ตัวอย่าง response data จากการเรียกดูแบบหลายรายการ
ข้อมูลต่อไปนี้เป็นผลลัพธ์ตัวอย่างจากการเรียก API ด้วย /product-masters?currentPage=1&pageSize=2
โดยที่ธุรกิจปัจจุบัน มีสินค้าในระบบทั้งหมด 314 รายการ
{
"total": 314,
"currentPage": 1,
"list": [
{
"id": 222671,
"type": 5,
"name": "1698325220-intelligent steel mouse",
"code": "",
"categoryId": null,
"categoryName": "",
"sellSettings": {
"vatType": 5,
"description": ""
},
"buySettings": {
"vatType": 7,
"description": ""
},
"mainProductId": 43053678,
"mainUnitId": 842206,
"mainUnitName": "หน่วยนับ",
"productLists": [
{
"id": 43053678,
"unitId": 842206,
"unitName": "หน่วยนับ",
"isMainProduct": true,
"sellPrice": 900.00000000,
"sellPriceWithVat": 900.00000000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": null,
"convertRatio": 1.0,
"hasMovement": true
}
]
},
{
"id": 28775002,
"type": 3,
"name": "1698325220-intelligent steel mouse",
"code": null,
"categoryId": null,
"categoryName": "",
"sellSettings": {
"vatType": 1,
"description": "Type Product"
},
"buySettings": {
"vatType": 5,
"description": null
},
"mainProductId": 51259427,
"mainUnitId": null,
"mainUnitName": "",
"productLists": [
{
"id": 51259427,
"unitId": null,
"unitName": "",
"isMainProduct": true,
"sellPrice": 100.00000000,
"sellPriceWithVat": 107.00000000,
"buyPrice": 0.0,
"buyPriceWithVat": 0.0,
"barcode": null,
"convertRatio": 1.0,
"hasMovement": false
}
]
}
]
}
- ในการกรณีที่ ระบุ
currentPage
เกินกว่า จำนวน page ที่มีข้อมูล จะได้ผลลัพธ์ของlist
เป็นรายการที่ไม่มีข้อมูล
การค้นหาสินค้าโดยการใช้ searchString
Client สามารถระบุคำค้นในการเรียกดูข้อมูลแบบหลายรายการได้ โดยการระบุคำค้นใน searchString
แทนการค้นหาด้วยคำที่ระบุจาก field ต่อไปนี้
name
- ชื่อสินค้าcode
- รหัสสินค้าbarcode
- รหัสบาร์โค้ดของสินค้า
- แนะนำให้ส่งคำค้นโดยค่าที่เข้ารหัส URL Parameter เพื่อแปลงอักขระพิเศษให้อยู่ในรูปที่ส่งผ่าน HTTP โดยเฉพาะกรณีที่คำค้นเป็นภาษาไทยหรือเป็นอักขระพิเศษ
- หาไม่พบรายการ จะได้รับผลรับเป็นรายการที่ไม่ข้อมูล
- การใช้
searchString
เป็นการค้นหาแบบ string contain matching ซึ่งผลลัพธ์ที่ได้จะมีค่าอย่างน้อย 1 field ที่มีคำค้นอยู่ในค่านั้น ๆ
ตัวอย่าง response data จากการค้นหาโดยใช้ searchString
ข้อมูลต่อไปนี้เป็นผลลัพธ์ตัวอย่างจากการเรียก API ด้วย /product-masters?searchString=%E0%B8%82%E0%B8%B2%E0%B8%AB%E0%B8%A1%E0%B8%B9
ด้วยคำค้นว่า ขาหมู
{
"total": 2,
"currentPage": 1,
"list": [
{
"id": 44451219,
"type": 5,
"name": "ขาหมูเยอรมันปรุงสำเร็จ",
"code": "KHAMOO",
"categoryId": 937775,
"categoryName": "อาหารสำเร็จ",
"sellSettings": {
"vatType": 3,
"description": "ขาหมูบรรจุห่อ"
},
"buySettings": {
"vatType": 3,
"description": "ขูหมาบรรจุแพ๊ค"
},
"mainProductId": 56666383,
"mainUnitId": 1,
"mainUnitName": "กล่อง",
"productLists": [
{
"id": 56666383,
"unitId": 1,
"unitName": "กล่อง",
"isMainProduct": true,
"sellPrice": 1000.00000000,
"sellPriceWithVat": 1070.00000000,
"buyPrice": 100.00000000,
"buyPriceWithVat": 107.00000000,
"barcode": "KAMU-BARCODE",
"convertRatio": 1.0,
"hasMovement": true
},
{
"id": 56666381,
"unitId": 19,
"unitName": "แพ๊ค",
"isMainProduct": false,
"sellPrice": 0.00000000,
"sellPriceWithVat": 0.00000000,
"buyPrice": 500.00000000,
"buyPriceWithVat": 535.00000000,
"barcode": "KAMU-PK-BAR",
"convertRatio": 5.00000000,
"hasMovement": true
},
{
"id": 56666382,
"unitId": 4096923,
"unitName": "ลัง",
"isMainProduct": false,
"sellPrice": 10000.00000000,
"sellPriceWithVat": 10700.00000000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": "",
"convertRatio": 12.00000000,
"hasMovement": true
}
]
},
{
"id": 44514403,
"type": 5,
"name": "ขาหมูอบน้ำผึ้งปรุงสำเร็จ",
"code": "",
"categoryId": null,
"categoryName": "",
"sellSettings": {
"vatType": 3,
"description": ""
},
"buySettings": {
"vatType": 3,
"description": ""
},
"mainProductId": 56731399,
"mainUnitId": 1,
"mainUnitName": "กล่อง",
"productLists": [
{
"id": 56731399,
"unitId": 1,
"unitName": "กล่อง",
"isMainProduct": true,
"sellPrice": 0.00000000,
"sellPriceWithVat": 0.00000000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": "",
"convertRatio": 1.0,
"hasMovement": true
},
{
"id": 56731398,
"unitId": 4110040,
"unitName": "ขีด",
"isMainProduct": false,
"sellPrice": 0.00000000,
"sellPriceWithVat": 0.00000000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": "",
"convertRatio": 0.20000000,
"hasMovement": true
}
]
}
]
}
การค้นหาสินค้าโดยการใช้ filter
Client สามารถค้นหาหรือกรองข้อมูลในการเรียกดูข้อมูลแบบหลายรายการได้ โดยการสร้าง filter expression object และระบุค่าที่ได้ใน filter
ซึ่งวิธีการนี้จะทำให้สามารถระบุการค้นหาตาม field value ของตัวสินค้าที่ต้องการได้ละเอียดมากขึ้น
ค่าของ filter
ต้องอยู่ในรูป JSON string ของ expression object list ซึ่งกำหนด format ของ expression object ดังนี้
Field | Type | Description |
---|---|---|
columnName | string | ชื่อ field ที่ต้องการค้นหา |
columnValue | string | ค่าที่ต้องการค้นหา |
columnPredicateOperator | string | ตัวระบุ logical operator สำหรับกรณีที่มี expression object มากกว่า 1 element มีค่า and หรือ or |
ชื่อ field ที่สามารถใช้ค้นหาได้ ได้แก่
name
= ชื่อสินค้าtype
= ประเภทของสินค้า โดยที่ columnValue จะต้องเป็น 1, 3 หรือ 5 ในรูป stringproductCode
= รหัสสินค้า โดยที่ columnValue จะต้องเป็น stringcategoryId
= Id ของ หมวดสินค้า โดยที่ columnValue จะต้องเป็น numeric string
- ค่าของ
filter
จะต้องอยู่ในรูป list of expression object เสมอ ถึงแม้จะมีเพียงแค่ element เดียว หากไม่ได้ใส่เป็น list จะได้รับ error HTTP 400 และ messagefilter is invalid
- หาก
columnValue
ไม่เป็นอยู่ใน type ที่ถูกต้องตามที่กำหนดของแต่ละ column จะได้รับ error HTTP 500 และ messageThe input string '{{value}}' was not in a correct format.
- แนะนำให้ serialize ค่าที่ได้ในรูปแบบ JSON และเข้ารหัส URL parameter ของค่าที่ได้ เพื่อแปลงอักขระพิเศษที่ใส่มาใน
columnValue
สามารถอ่านแนวคิดและวิธีการทำงานของ filter express object ได้จากบทความของ FLOWACCOUNT TECH BLOG
การค้นหาและการจัดเรียงสำหรับเว็บแอปพลิเคชั่น (Generic Searching and Sorting)
การ เรียงลำดับผลลัพธ์โดยการใช้ sortBy
Client สามารถเรียงลำดับของผลลัพธ์ในรายการได้ โดยการสร้าง sorting expression object และระบุค่าที่ได้ใน sortBy
ค่าของ sortBy
ต้องอยู่ในรูป JSON string ของ expression object list ซึ่งกำหนด format ของ expression object ดังนี้
Field | Type | Description |
---|---|---|
name | string | ชื่อ field ที่ต้องการจัดเรียง |
sortOrder | string | ทิศทางในการจัดเรียง asc สำหรับเรียงจากน้อยไปมาก และ desc สำหรับมากไปน้อย |
ชื่อ field ที่สามารถในระบุเพื่อเรียงได้ ได้แก่
name
= ชื่อสินค้าtype
= ประเภทของสินค้าproductCode
= รหัสสินค้า กรณีที่ value เป็น null จะถูกเรืยงลำดับมาก่อน value ที่มีค่าcategoryId
= Id ของ หมวดสินค้า
- โดยทั่วไป หากค่าของ
sortBy
ไม่ถูกต้อง จะได้รับ error HTTP 400 และ messagesortBy is invalid
code51024