Forum Discussion
Setting Host and Date header fields in Web query
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]),
- Anonymous1 year ago
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.
5 Replies
- AnonymousNot applicable
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.- AnonymousNot applicable
Hi mbowler,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround so that other users can benefit as well. And if you're still looking for guidance, feel free to give us an update, we’re here for you.
Best Regards,
Hammad.
- mbowlerHelper I
Hi Hammad, thanks for your reply.
I can see that the if M sets the Host to the base of the query url then that will be fine as this is what the API is expecting but unfortunately Date header needs to be the exact same string as was used in the generation of the HMAC. The encoded text used to generate the HMAC is a combination of the full query and the Date:
"GET
https://the.host.com/api/events?quantity=100
Tue, 19 Aug 2025 10:10:18 GMT"I find it curious that M restricts the setting of Date and Host headers for security reasons because the same restriction is not applied to Power Automate, I was easily able to create a HTTP action and set these fields. I would have used PA to automate the getting of the data from this API except for the problem of dynamically generating the HMAC in PA online. There are paid-for connectors available but I'm looking for no-cost solution.
Is it usual practice to set the Accept as Solution when the solution is "there is no solution"? If so, I'll set it.
- Shahid12523Community Champion
Host: Always set automatically from the URL → you can’t override.
Date: Blocked too → can’t set in M. Use API-specific alt header (x-ms-date, x-date, etc.) if supported.
If API only accepts Date: you’ll need a proxy (Azure Function/API Management) to inject it.
In short: You can’t set Host/Date in Power Query. Use an alt header or a proxy.