Forum Discussion
Power BI Service Trims Trailing Slash in Web.Contents Base URL – Causes API Error (LeafLink)
- 1 year ago
Hi DataIkseer
The Root Cause
Power BI Service treats
Web.Contentsdifferently — particularly in how it constructs and evaluates the base URL and relative paths. One specific behavior is that:-
Trailing slashes in the base URL can be trimmed or misinterpreted when used directly in
Web.Contents, especially if you're using query parameters or dynamic URL construction.
This is more likely to cause issues if:
-
The API requires an exact match of the endpoint structure, including trailing slashes.
You're using the
Web.Contentsoverload that splits base URL and query, and the service tries to "optimize" or pre-evaluate URLs for gateway compatibility.Recommended Fix
Use the fully constructed URL (with query parameters) as a single string to avoid Power BI Service manipulating the structure.
Here's how to rework your
fetchPagefunction safely:
fetchPage = (offset as number) =>
let
fullUrl = baseUrl & "?" & Uri.BuildQueryString([
limit = Number.ToText(limit),
offset = Number.ToText(offset)
]),
Source = Web.Contents(
fullUrl,
[
Headers = [
#"Authorization" = "Token " & token,
#"Content-Type" = "application/json"
]
]
),
JsonResponse = Json.Document(Source)
in
JsonResponseMicrosoft Documentation Note
This quirk isn't very well-documented, but it's been raised in several forums and GitHub issues, especially around:
-
Relative path handling
-
Base URL and privacy levels
-
URL encoding and trailing slash behavior
So yes — it's expected behavior but under-documented. You’re not doing anything wrong; this is a subtle platform inconsistency between Desktop and Service.
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!
-
Hi DataIkseer ,
Thank you for reaching out to Microsoft Fabric Community Forum.
johnbasha33 Thank you for your quick response.
Alongside the solution provided by the super user, you may also consider trying the following.
Yes, this is a known behavior — the way Web.Contents handles URLs can differ between Power BI Desktop and the Service. To avoid this issue, it’s recommended to use the RelativePath option inside Web.Contents. This ensures Power BI constructs the full URL properly without trimming or misinterpreting it.
let
limit = 100,
baseUrl = "https://app.leaflink.com/api/v2/",
token = "XXXXXXXXXX",
fetchPage = (offset as number) =>
let
query = [
limit = Number.ToText(limit),
offset = Number.ToText(offset)
],
Source = Web.Contents(
baseUrl,
[
RelativePath = "products/",
Query = query,
Headers = [
#"Authorization" = "Token " & token,
#"Content-Type" = "application/json"
]
]
),
JsonResponse = Json.Document(Source)
in
JsonResponse,
firstPage = fetchPage(0),
totalCount = firstPage[count],
pages = List.Generate(
() => [offset = 0, page = firstPage],
each [offset] < totalCount,
each [offset = [offset] + limit, page = fetchPage([offset] + limit)]
),
allPages = {firstPage} & List.Transform(pages, each [page]),
resultsList = List.Combine(List.Transform(allPages, each try _[results] otherwise {}))
in
resultsList
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! |
Regards,
B Manikanteswara Reddy
Hi DataIkseer ,
We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
|
Please don't forget to give a "Kudos " – I’d truly appreciate it! |
Regards,
B Manikanteswara Reddy
- Anonymous1 year agoNot applicable
Hi DataIkseer ,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Please don't forget to give a "Kudos " – I’d truly appreciate it!
Regards,
B Manikanteswara Reddy
- Anonymous1 year agoNot applicable
Hi DataIkseer ,
May I ask if you have gotten this issue resolved?
If it is solved, please mark the helpful reply or share your solution and accept it as solution, it will be helpful for other members of the community who have similar problems as yours to solve it faster.
Please don't forget to give a "Kudos " – I’d truly appreciate it!
Regards,
B Manikanteswara Reddy