Web.Contents
What a web address answers, as a binary: a file to read with Csv.Document, Json.Document or another reader.
Group: Files and documents. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Web.Contents(url as text, optional options as nullable record) as binary
| Parameter | Type | Description |
|---|---|---|
url | text | The address, http:// or https://. |
options | nullable record optional | RelativePath, Query, Headers, Content, ApiKeyName and ManualStatusHandling. |
Returns
binary. The answer's body, fetched when something reads it.
Remarks
- RelativePath is added to the address after a slash; Query's fields are added as ?name=value&..., encoded for an address. Headers are sent with the request. Content (text or binary) makes the request a POST with that body.
- A key belongs in the sign-in, never in the query's M. The studio asks for the sign-in (Anonymous, Web API key or Basic) the first time it reads the address; a Web API key goes in a header, or in the query value that ApiKeyName names.
- An answer of 400 or more is an error, unless ManualStatusHandling lists its status: then the body is given, and
Value.Metadataof it has Response.Status. - The request goes out when the bytes are read, not when
Web.Contentsruns: atryaroundWeb.Contentsalone doesn't see a failed request; put it around the step that reads the bytes. - On OpenBI Server, the server's web guard checks every address and every redirect before it is read.
Examples
A CSV file on the web
Csv.Document(Web.Contents("https://data.example.com/exports/prices.csv"))
Result: not shown here: it reads a web address, which the docs' build doesn't.
A web API with a path, a query and a header
The request goes to https://api.example.com/v1/orders?status=open.
Json.Document(Web.Contents("https://api.example.com", [
RelativePath = "v1/orders",
Query = [status = "open"],
Headers = [Accept = "application/json"]
]))
Result: not shown here: it calls a web API, which the docs' build doesn't.
Nothing is fetched until the bytes are needed
Web.Contents("https://data.example.com/exports/prices.csv") is binary
true
The value is a binary at once; the address is read only when a reader such as Csv.Document uses it.
Related functions
Csv.Document, Json.Document, Value.Metadata, Binary.Buffer, OData.Feed.