---
title: OData.Feed – เชื่อมต่อบริการ OData
url: https://www.thepexcel.com/functions/power-query/accessing-data-functions/odata-feed/
type: function-explainer
program: Power Query
syntax: "OData.Feed(serviceUri as text, optional headers as nullable record, optional options as any) as any"
date: 2025-12-12
updated: 2025-12-23
scores:
  popularity: 6
  difficulty: 4
  usefulness: 6
---

# OData.Feed – เชื่อมต่อบริการ OData

> OData.Feed เชื่อมต่อบริการ OData และดึงข้อมูลจาก OData endpoints ซึ่งมักจะเป็น API ที่มีโครงสร้างมาต

## คำอธิบาย

OData.Feed เชื่อมต่อบริการ OData และดึงข้อมูลจาก OData endpoints ซึ่งมักจะเป็น API ที่มีโครงสร้างมาตรฐาน

## Syntax

```excel
OData.Feed(serviceUri as text, optional headers as nullable record, optional options as any) as any
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| serviceUri | Yes | text |  | URL ของบริการ OData ที่ต้องการเชื่อมต่อ เช่น https://services.odata.org/V4/TripPinService |
| headers | No | record | null | Headers HTTP เพิ่มเติมสำหรับการส่งคำขอ เช่น authentication headers |
| options | No | record | null | ตัวเลือกการตั้งค่าเพิ่มเติม เช่น Timeout, ODataVersion, Concurrent เป็นต้น |

## ตัวอย่าง

### 1. เชื่อมต่อ OData service แบบพื้นฐาน

```excel
let
    Source = OData.Feed("https://services.odata.org/V4/TripPinService")
in
    Source
```

**ผลลัพธ์:** `ตารางที่แสดงทรัพยากร (resources) ทั้งหมดที่มีใน OData service นั้น`

ใช้ OData.Feed เพื่อเชื่อมต่อกับ TripPin OData service และได้รับข้อมูลทั้งหมด

### 2. ระบุ OData version และ timeout

```excel
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 วินาที`

ระบุเวอร์ชัน OData และกำหนด timeout เพื่อควบคุมประสิทธิภาพ

### 3. เชื่อมต่อด้วย custom headers (authentication)

```excel
let
    ServiceUri = "https://api.example.com/odata",
    Headers = [Authorization = "Bearer eyJhbGc..."],
    Source = OData.Feed(ServiceUri, Headers, null)
in
    Source
```

**ผลลัพธ์:** `ข้อมูลจาก OData service ที่ต้องการ authentication`

ใช้ custom headers เพื่อส่งผ่าน API token หรือ bearer token สำหรับการยืนยันตัวตน

### 4. เชื่อมต่อ SharePoint Online list

```excel
let
    ServiceUri = "https://tenant.sharepoint.com/sites/sitename/_api/v2.0",
    Source = OData.Feed(ServiceUri, [#"Authorization" = "Bearer " & token])
in
    Source
```

**ผลลัพธ์:** `ข้อมูลจาก SharePoint Online`

เชื่อมต่อ SharePoint Online เพื่อดึงข้อมูลจาก Lists ผ่าน OData endpoint

## หมายเหตุเพิ่มเติม

- ใช้ Power Query UI Navigator เพื่อเลือก table/entity ที่ต้องการแทนการเขียน code เองเมื่อเป็นไปได้

- ตรวจสอบว่า OData service เปิดให้เข้าถึงเฉพาะ entities บางตัวหรือไม่ ด้วยการดูเอกสาร API

- ใช้ Query option (เช่น $filter, $select, $top) เพื่อ filter และ select columns ที่ต้องการจากบริการ

- หากต้องการ incremental refresh ให้พิจารณา $filter ด้วย timestamp หรือ modified date

- ทดสอบ connection กับ Power Query Desktop ก่อนสร้าง Power BI model เพื่อหลีกเลี่ยง deployment issues

## คำถามที่พบบ่อย

**Q: OData.Feed ต่างจาก Web.Contents ยังไง?**

OData.Feed รองรับ OData protocol โดยเฉพาะ และจัดการ navigation, filtering, sorting อัตโนมัติ ส่วน Web.Contents เป็นเพียง HTTP request ทั่วไป ต้องจัดการ JSON/XML parsing เอง

**Q: ต้องใช้ ODataVersion เวอร์ชันไหน?**

OData V4 เป็นเวอร์ชันปัจจุบันที่แนะนำ บางบริการเก่าอาจใช้ V3 ตรวจสอบเอกสาร API ของบริการที่คุณเชื่อมต่อ

**Q: Timeout default คือเท่าไหร่?**

600 วินาที (10 นาที) หากต้องการเปลี่ยน ให้ระบุในตัวเลือก options โดยใช้ Timeout parameter

**Q: ต้องใช้ authentication ทุกครั้งไหม?**

ขึ้นอยู่กับบริการ OData บางตัวเปิดเข้าถึงได้ทั่วไป บางตัวต้อง API key, Bearer token หรือ credentials

**Q: EnableBatch ใช้สำหรับอะไร?**

สำหรับการส่งคำขอหลายตัวในการเรียกเดียว (batch request) จะช่วยเมื่อ URI มีความยาวมากเกินไป หรือต้องการ optimize network traffic

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn: OData.Feed](https://learn.microsoft.com/en-us/powerquery-m/odata-feed) _(official)_
- [OData Protocol Official Specification](https://www.odata.org/) _(article)_
- [Power Query M Language Reference](https://learn.microsoft.com/en-us/powerquery-m/) _(official)_

---

_Source: [https://www.thepexcel.com/functions/power-query/accessing-data-functions/odata-feed/](https://www.thepexcel.com/functions/power-query/accessing-data-functions/odata-feed/)_
