Step 3: Enter API URL, Handle Headers, and Authentication (Optional)
If your API requires headers (like API keys or tokens), use the following structure:
- With the blank query selected, go to the Advanced Editor.
- Replace the default code with the following (customized as per your API):
let
TokenReq = Web.Contents("https://apigateway.muvi.com/get-user-token-details",[
Headers = [
#"Content-Type" = "application/json"
],
Content = Json.FromValue([
secret_key = secret_key,
app_id = app_id
])
]),
TokenJson = Json.Document(TokenReq),
response = TokenJson[response],
access_token = response[access_token],
AnalyticReq = Web.Contents("https://apigateway.muvi.com/analytics/custom-user-report",[
Headers = [
Authorization = "Bearer " & access_token,
#"Content-Type" = "application/json"
],
Content = Json.FromValue([
lifetime = lifetime
])
]),
AnalyticRes = Json.Document(AnalyticReq),
data = AnalyticRes[data]
in
data
Step 4: Transform Data
- After connecting, Power BI will display the API data in a structured format.
- Use the Power Query Editor to expand, filter, and transform the data as needed.
Step 6: Load the Data
- Click Close & Apply to load the data into Power BI for reporting and visualization.
Additional Tips:
- Use pagination logic if your API returns data in pages.
- Consider using RelativePath and Query parameters in Web. Contents for complex URL structures.
- A schedule refresh may require setting up credentials in Power BI Service.
Example with Pagination (Basic):
let
Page1 = Json.Document(Web.Contents("https://api.example.com/data?page=1")),
Page2 = Json.Document(Web.Contents("https://api.example.com/data?page=2")),
Combined = List.Combine({Page1, Page2})
in
Combined