Forum Discussion

DataIkseer's avatar
DataIkseer
Regular Visitor
1 year ago
Solved

Power BI Service Trims Trailing Slash in Web.Contents Base URL – Causes API Error (LeafLink)

I'm encountering an issue while integrating LeafLink's API into Power BI using Web.Contents. Everything works fine in Power BI Desktop, but after publishing to the Power BI Service, the scheduled ref...
  • johnbasha33's avatar
    1 year ago

    Hi DataIkseer 

    The Root Cause

    Power BI Service treats Web.Contents differently — 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.Contents overload 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 fetchPage function 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
    JsonResponse

    Microsoft 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 !!