Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
ECorona
Advocate I
Advocate I

Trying to pass a Bearer token using the OData.Feed function.

Hello, I'm trying to consume a REST API using the OData.Feed function, I have the URL and the bearer token to perform the request, but I'm getting the error: 

"Expression.Error: OData: The header with name 'Headers' has a value type 'Record' that is invalid. Only DateTime, Logical, Number, and Text are supported."

 

The URL and the bearer token are valid, I can use them to perform a request in post man.

 

This is the code I'm trying to run (the token and the URL has been censored for security reasons):

 

let 
token = "",
url = "",

//Source = OData.Feed(url, null, [Headers = [Authorization = token] ])
Source = OData.Feed(url, [Headers=[#" Authorization  " = token]])

in
Source

The code has been inspired from the answer found here but the error message seems to be different.

Solved: Re: How authenticate to OData feed that uses Token... - Microsoft Fabric Community

2 REPLIES 2
rubayatyasmin
Super User
Super User

Hi, @ECorona 

 

The error message you're getting suggests that the headers you're passing to the OData.Feed function are not formatted correctly.

The OData.Feed function in Power Query M takes three parameters:

  • url (text): The URL of the data feed.
  • null or an optional record parameter to specify a relativePath, query, or headers
  • options (record) : An optional record parameter that may be specified to control the following options:
    • Implementation (text): The implementation of OData to use. The available values are "2.0" and "4.0".
    • Query (list): A list of queries to perform on the data feed.
    • Headers (record): A record of values to be used as headers in the HTTP request.

The problem seems to be with how you're passing your headers. You need to pass the headers as part of the options record, not the second parameter. The Authorization header usually starts with the word Bearer followed by a space and then the token.

Here's how you can correct your code:

 

let
token = "Bearer " & "<YourTokenHere>",
url = "<YourUrlHere>",
Source = OData.Feed(url, null, [Headers=[Authorization = token]])
in
Source

 

You replace <YourTokenHere> and <YourUrlHere> with your actual token and URL.

The corrected code passes the headers correctly, by including the Bearer keyword before the token. This is the standard way of passing bearer tokens in the Authorization header.

 

refer:

https://learn.microsoft.com/en-us/powerquery-m/odata-feed

 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Hello,

 

I'd like to ask, if I'm gonna use two headers for my odata source, what would the format of the query would be? Is it like this?

Source = OData.Feed(url, null, [Headers=[Authorization = token], [customheader = key])

Thank a bunch!

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.