Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
techgs
Regular Visitor

Passing Variables into API URL - without preventing PBI Server dataset refresh

Hi,
Needed to add a dynamic varaible to my API call used a function to pass the ID number and then pull the relevant field per ID - was very happy when it all seemed to work ok in desktop.
Published to the PowerBI server and got a "This dataset includes a dynamic data source. Since dynamic data sources aren't refreshed in the Power BI service,"
I had done some research and it seems I need to trick the PowerBI server into not treating this like a dynamic data source, possibly by moving the variable down to Web.contents - but cant get it to work.

Current code is....

 

(projectIDVariabl) =>

let
url = "https://api.workguru.io/api/ClientTokenAuth/Authenticate/api/client/v1/tokenauth",

body = "{ ""ApiKey"": ""XXX"", ""Secret"": ""XXX"" }",
tokenResponse = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] )),
AccessToken = tokenResponse[accessToken],
AccessTokenHeader = "Bearer " & AccessToken,


data_url = "https://api.workguru.io/api/services/app/Project/GetProjectById?id="& Number.ToText(projectIDVariabl)&"&includeProductImages=false&includeLineItemCustomFields=true",
data_body = "{
""authorization"": """& AccessTokenHeader & """,
""content-type"": ""application/json""
}",

GetGroups = Json.Document(
Web.Contents(
data_url,
[
Headers = Json.Document(data_body)
]
)
),
#"Converted to Table" = Record.ToTable(GetGroups),
Value1 = #"Converted to Table"{0}[Value],
#"Converted to Table1" = Record.ToTable(Value1),
#"Transposed Table" = Table.Transpose(#"Converted to Table1"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"tenantId", Int64.Type}, {"projectNo", type text}, {"projectName", type text}, {"description", type text}, {"startDate", type datetime}, {"dueDate", type datetime}, {"clientId", Int64.Type}, {"billingClientId", Int64.Type}, {"projectGroupId", type any}, {"clientPurchaseOrder", type any}, {"status", type text}, {"warehouse", type any}, {"warehouseId", type any}, {"contactId", Int64.Type}, {"contact", type any}, {"billingClient", type any}, {"client", type any}, {"recurringProjectId", type any}, {"recurringProject", type any}, {"customFieldValues", type any}, {"invoices", type any}, {"timeSheets", type any}, {"notes", type any}, {"files", type any}, {"taskLineItems", type any}, {"productLineItems", type any}, {"milestones", type any}, {"stockUsage", type any}, {"clientCreditNotes", type any}, {"completedDate", type any}, {"asset", type any}, {"assetId", type any}, {"purchaseOrders", type any}, {"quoteId", type any}, {"quote", type any}, {"reportingCategoryOption1Id", Int64.Type}, {"reportingCategoryOption2Id", type any}, {"reportingCategoryOption1", type any}, {"reportingCategoryOption2", type any}, {"currency", type text}, {"exchangeRate", Int64.Type}, {"projectGroup", type any}, {"projectManagerId", Int64.Type}, {"projectManager", type any}, {"forecastTime", Int64.Type}, {"totalTime", Int64.Type}, {"total", Int64.Type}, {"baseCurrencyTotal", Int64.Type}, {"documentStorageId", type any}, {"externalSystemId", type any}, {"externalSystemWebhookKey", type any}, {"supplierCreditNotes", type any}, {"useStaffRates", type logical}, {"totalInvoiced", Int64.Type}, {"totalTax", Int64.Type}, {"cost", Int64.Type}, {"forecastCost", Int64.Type}, {"profit", Int64.Type}, {"profitPercentage", Int64.Type}, {"isProductionJob", type logical}, {"phases", type any}, {"customFieldGroupId", type any}, {"customFieldGroup", type any}, {"isDeleted", type logical}, {"deleterUserId", type any}, {"deletionTime", type any}, {"lastModificationTime", type any}, {"lastModifierUserId", type any}, {"creationTime", type datetime}, {"creatorUserId", Int64.Type}, {"id", Int64.Type}}),
#"Expanded customFieldValues" = Table.ExpandListColumn(#"Changed Type", "customFieldValues"),
#"Expanded customFieldValues1" = Table.ExpandRecordColumn(#"Expanded customFieldValues", "customFieldValues", {"customFieldId", "value"}, {"customFieldValues.customFieldId", "customFieldValues.value"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded customFieldValues1", each ([customFieldValues.customFieldId] = 2199))
in
#"Filtered Rows"




1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @techgs,

Perhaps you can try to use option parameters in web connector if they help you to handle this scenario:

let
    GetProejct=(projectID as number) =>
    let
        projectIDVariabl = projectID,
        root_url = "https://api.workguru.io",
        body = "{ ""ApiKey"": ""XXX"", ""Secret"": ""XXX"" }",
        tokenResponse = Web.Contents(
            root_url,
            [
                Headers = [#"Content-Type" = "application/json"],
                RelativePath = "/api/ClientTokenAuth/Authenticate/api/client/v1/tokenauth",
                Content = Text.ToBinary(body)
            ]
        ),
        AccessToken = Json.Document(tokenResponse)[accessToken],
        projectResponse = Web.Contents(
            root_url,
            [
                RelativePath = "/api/services/app/Project/GetProjectById",
                Headers = [#"content-type": "application/json", authorization = "Bearer " & AccessToken],
                Query = [
                    id = Number.ToText(projectIDVariabl),
                    includeProductImages = "false",
                    includeLineItemCustomFields = "true"
                ]
            ]
        ),
        GetGroups = Json.Document(projectResponse)
    in
        GetGroups
in 
    GetProejct

Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query An...

Chris Webb's BI Blog: Handling Multiple URL Query Parameters With The Same Name Using Web.Contents I...

Regards,

Xiaoxin Sheng

 

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @techgs,

Perhaps you can try to use option parameters in web connector if they help you to handle this scenario:

let
    GetProejct=(projectID as number) =>
    let
        projectIDVariabl = projectID,
        root_url = "https://api.workguru.io",
        body = "{ ""ApiKey"": ""XXX"", ""Secret"": ""XXX"" }",
        tokenResponse = Web.Contents(
            root_url,
            [
                Headers = [#"Content-Type" = "application/json"],
                RelativePath = "/api/ClientTokenAuth/Authenticate/api/client/v1/tokenauth",
                Content = Text.ToBinary(body)
            ]
        ),
        AccessToken = Json.Document(tokenResponse)[accessToken],
        projectResponse = Web.Contents(
            root_url,
            [
                RelativePath = "/api/services/app/Project/GetProjectById",
                Headers = [#"content-type": "application/json", authorization = "Bearer " & AccessToken],
                Query = [
                    id = Number.ToText(projectIDVariabl),
                    includeProductImages = "false",
                    includeLineItemCustomFields = "true"
                ]
            ]
        ),
        GetGroups = Json.Document(projectResponse)
    in
        GetGroups
in 
    GetProejct

Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query An...

Chris Webb's BI Blog: Handling Multiple URL Query Parameters With The Same Name Using Web.Contents I...

Regards,

Xiaoxin Sheng

 

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much - that does the job nicely.
I just needed to update the colon to an equals in this line.

 Headers = [#"content-type": "application/json", authorization = "Bearer " & AccessToken],

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.