Web.Headers
Accessing DataReturns the HTTP response headers for the specified URL as a record.
Syntax
Web.Headers(url as text, optional options as nullable record) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
url | text | Yes | The URL to send the HTTP HEAD request to. |
options | record | No | An optional record with request options. Supports the same options as Web.Contents, including Headers (to set request headers), Timeout, and IsRetry. |
Return Value
record — A record where each field name is an HTTP response header name and each field value is the corresponding header value as text.
Remarks
Web.Headers sends an HTTP HEAD request to the specified URL and returns the response headers as a Power Query record. Each field in the record is an HTTP response header name and its value as text. This is useful for inspecting metadata about a resource — its content type, size, caching policy, last modified timestamp, or any other server-provided header — without downloading the full response body.
HTTP HEAD vs GET: A HEAD request retrieves only the response headers, not the body. The server processes the request as if it were a GET but sends back only headers. This makes Web.Headers efficient for checking whether a file has changed (via Last-Modified or ETag) before deciding whether to download it with Web.Contents.
Authentication: Web.Headers respects the same credential configuration as Web.Contents. If the URL requires authentication, configure credentials in the Power Query data source settings dialog for the corresponding URL. The function shares credential scope with Web.Contents calls to the same origin.
Common response headers and their uses:
- Content-Type — the MIME type of the resource (e.g., text/csv, application/json, application/vnd.ms-excel). Use to determine the correct parsing function.
- Last-Modified — the date and time the resource was last changed, as a text value. Compare against a stored value to detect updates.
- ETag — an entity tag (opaque hash) representing the resource version. Use for cache validation.
- Content-Length — the size of the body in bytes, as a text value. Estimate download size before calling Web.Contents.
- Content-Disposition — may include the suggested file name for a download.
Accessing headers: Record field names include hyphens (e.g., Content-Type, Last-Modified). Access them using the standard record field syntax: Headers[Content-Type]. If a header name conflicts with an M keyword or contains special characters, use Record.Field(Headers, "Header-Name").
Query folding: Not supported.
Examples
Example 1: Retrieve all response headers for a URL
```powerquery
Web.Headers("https://example.com/data.csv")Example 2: Read the Content-Type header to identify the file format
```powerquery
let
Headers = Web.Headers("https://example.com/report"),
ContentType = Headers[Content-Type]
in
ContentTypeExample 3: Check the Last-Modified date of a resource
```powerquery
let
Headers = Web.Headers("https://example.com/report.xlsx"),
LastModified = Headers[Last-Modified]
in
LastModifiedExample 4: Send a HEAD request with a custom Authorization header
```powerquery
Web.Headers(
"https://api.example.com/dataset",
[Headers = [Authorization = "Bearer mytoken123"]]
)