The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
I'm trying to get data from a REST API that requires the Host and Date fields to be set in the GET query as they are used to validate the HMAC authentication string that is passed in the Authorization field.
Web.Contents throws an error saying "Expression.Error: The 'Host' header must be modified using the appropriate property or method." and I get the same for Date if I try to add it.
I've tried using a custom connector for the query but the result is the same. Any ideas on how this can be acheived? And why the heck aren't these fields settable ??!!
My code:
_Headers = [
#"Host" = "the.host.com",
#"Date" = _Date,
#"Authorization" = HMAC_Output,
#"Content-Type"= "application/json"
],
response = Web.Contents(_Uri, [Headers=_Headers]),
Hi @mbowler,
Thanks for reaching out to the Microsoft fabric community forum.
Power Query blocks you from setting certain HTTP headers directly (Host, Date, Referer, Cookie, and a few others) because these are considered restricted and are controlled by the underlying HTTP stack for security and protocol compliance reasons.
For Host, Power Query automatically sets it based on the URL you pass to Web.Contents. The only way to change it is to make the request to that exact host in your _Uri, you can’t override it in the Headers record.
For Date it’s similar, Power Query will generate it automatically when needed, and it can’t be injected via the Headers parameter. If your API requires a specific timestamp for HMAC signing, you’ll need to generate the timestamp in M. Then use it when building your HMAC signature and pass it to the API in a custom header name (e.g. x-my-date) if the API supports it, or ensure the server uses the auto-generated Date header in the validation.
Unfortunately, there’s no supported way to override those restricted headers from within M code, even in a custom connector it’s a limitation of the Power Query engine. If your API requires your exact Host and Date header values, the only workaround would be to make the call outside of Power Query (e.g. via an Azure Function, API gateway, or other middleware) and then pull the results into Power Query.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Hammad.