OData.Feed เชื่อมต่อบริการ OData และดึงข้อมูลจาก OData endpoints ซึ่งมักจะเป็น API ที่มีโครงสร้างมาตรฐาน
=OData.Feed(serviceUri as text, optional headers as nullable record, optional options as any) as any
=OData.Feed(serviceUri as text, optional headers as nullable record, optional options as any) as any
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| serviceUri | text | Yes | URL ของบริการ OData ที่ต้องการเชื่อมต่อ เช่น https://services.odata.org/V4/TripPinService | |
| headers | record | Optional | null | Headers HTTP เพิ่มเติมสำหรับการส่งคำขอ เช่น authentication headers |
| options | record | Optional | null | ตัวเลือกการตั้งค่าเพิ่มเติม เช่น Timeout, ODataVersion, Concurrent เป็นต้น |
let Source = OData.Feed("https://services.odata.org/V4/TripPinService") in Sourcelet
Source = OData.Feed("https://services.odata.org/V4/TripPinService")
in
Source
ตารางที่แสดงทรัพยากร (resources) ทั้งหมดที่มีใน OData service นั้น
let ServiceUri = "https://services.odata.org/V4/TripPinService", Options = [ ODataVersion = 4, Timeout = 300 ], Source = OData.Feed(ServiceUri, null, Options) i…let
ServiceUri = "https://services.odata.org/V4/TripPinService",
Options = [
ODataVersion = 4,
Timeout = 300
],
Source = OData.Feed(ServiceUri, null, Options)
in
Source
ตารางข้อมูล OData V4 ที่มี timeout 300 วินาที
let ServiceUri = "https://api.example.com/odata", Headers = [Authorization = "Bearer eyJhbGc..."], Source = OData.Feed(ServiceUri, Headers, null) in Sourcelet
ServiceUri = "https://api.example.com/odata",
Headers = [Authorization = "Bearer eyJhbGc..."],
Source = OData.Feed(ServiceUri, Headers, null)
in
Source
ข้อมูลจาก OData service ที่ต้องการ authentication
let ServiceUri = "https://tenant.sharepoint.com/sites/sitename/_api/v2.0", Source = OData.Feed(ServiceUri, [#"Authorization" = "Bearer " & token]) in Sourcelet
ServiceUri = "https://tenant.sharepoint.com/sites/sitename/_api/v2.0",
Source = OData.Feed(ServiceUri, [#"Authorization" = "Bearer " & token])
in
Source
ข้อมูลจาก SharePoint Online
OData.Feed รองรับ OData protocol โดยเฉพาะ และจัดการ navigation, filtering, sorting อัตโนมัติ ส่วน Web.Contents เป็นเพียง HTTP request ทั่วไป ต้องจัดการ JSON/XML parsing เอง
OData V4 เป็นเวอร์ชันปัจจุบันที่แนะนำ บางบริการเก่าอาจใช้ V3 ตรวจสอบเอกสาร API ของบริการที่คุณเชื่อมต่อ
600 วินาที (10 นาที) หากต้องการเปลี่ยน ให้ระบุในตัวเลือก options โดยใช้ Timeout parameter
ขึ้นอยู่กับบริการ OData บางตัวเปิดเข้าถึงได้ทั่วไป บางตัวต้อง API key, Bearer token หรือ credentials
สำหรับการส่งคำขอหลายตัวในการเรียกเดียว (batch request) จะช่วยเมื่อ URI มีความยาวมากเกินไป หรือต้องการ optimize network traffic
OData.Feed ใช้สำหรับเชื่อมต่อและเรียกข้อมูลจากบริการ OData (Open Data Protocol) ซึ่งเป็นโปรโตคอลมาตรฐานสำหรับการเข้าถึงข้อมูลผ่าน REST API
ฟังก์ชันนี้มีประโยชน์มากเมื่อคุณต้องการดึงข้อมูลจากบริการคลาวด์หรือเซิร์ฟเวอร์ที่รองรับ OData เช่น SAP, Microsoft Dynamics, SharePoint Online หรืออื่น ๆ
ตัวอย่างการใช้งาน:
– เชื่อมต่อ SharePoint Online เพื่อดึงข้อมูลจาก Lists
– ดึงข้อมูลจาก Microsoft Dynamics 365
– เข้าถึง SAP OData services
– เชื่อมต่อ REST API ที่มี OData support
ส่วนตัวผม มักใช้ OData.Feed เมื่อสร้าง Power BI models ที่ต้อง refresh ข้อมูลจากระบบภายนอกอย่างอัตโนมัติ เพราะมันจัดการ authentication และ data transformation ได้ค่อนข้างสะดวก 😎