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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
LeninD
New Member

Refresh issue - Web.content within a function

Hi  Power Bi community,

 

I am a little bit new in Power Bi, and I am facing an issue when I refresh the data source on the service page.

 

The code is the following:

/*

let
Source = Json.Document(Web.Contents("api.xxxxcom", [RelativePath="/xxxxx/authentication/login",Query=[username=API_Username, password=API_Password], Headers=[#"Ocp-Apim-Subscription-Key"=API_SubscriptionKey]]))[userCode],
EarliermachineItemNumber = Table.SelectColumns(API_GetMachineMetadata, "machineItemNumber"),
#"Changed Type1" = Table.TransformColumnTypes(EarliermachineItemNumber,{{"machineItemNumber", type text}}),
Token = Table.AddColumn(#"Changed Type1", "Request", (earlier) => Json.Document(Web.Contents("//api.xxxxcom", [RelativePath="/xxxx/v2/machines/" & Text.From(earlier[machine]) & "/info", Headers=[#"X-Auth-Token"=Source, #"Ocp-Apim-Subscription-Key"=API_SubscriptionKey]]))),
#"Expanded Request" = Table.ExpandRecordColumn(Token, "Request", {"machineItemNumber", "machineId", "machineName", "machineCompany", "machineSite", "machineType", "machineModel", "machineLatitude", "machineLongitude", "machineTimeZone", "machineLastContact", "machineLastData"}, {"machineItemNumber.1", "machineId", "machineName", "machineCompany", "machineSite", "machineType", "machineModel", "machineLatitude", "machineLongitude", "machineTimeZone", "machineLastContact", "machineLastData"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Request",{{"machineLastContact", type datetime}, {"machineLastData", type datetime}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"machineItemNumber.1"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"machineLastContact", Order.Descending}}),
#"Merged Queries" = Table.NestedJoin(#"Sorted Rows", {"machineItemNumber"}, SQL_MachineComments, {"machine_itemnumber"}, "SQL_MachineComments", JoinKind.LeftOuter),
#"Expanded SQL_MachineComments" = Table.ExpandTableColumn(#"Merged Queries", "SQL_MachineComments", {"updated", "comments"}, {"updated", "comments"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded SQL_MachineComments",{"machineItemNumber", "machineId", "machineName", "machineCompany", "machineSite", "machineType", "machineModel", "machineLatitude", "machineLongitude", "machineTimeZone", "machineLastContact", "machineLastData", "comments", "updated"})
in
#"Reordered Columns"

*/

I have uncertainty in the following line:

Token = Table.AddColumn(#"Changed Type1", "Request", (earlier) => Json.Document(Web.Contents("api.xxx.com", [RelativePath="/xxx/v2/xxxx/" & Text.From(earlier[machineItemNumber]) & "/info", Headers=[#"X-Auth-Token"=Source, #"Ocp-Apim-Subscription-Key"=API_SubscriptionKey]]))),

 

Thanks for all the help 

🙂

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @LeninD 

Does the query work in power bi desktop?

If it is ok, does it prompt with a window to let you enter credential?

Is the authentication written in web url directly?

 

Best Regards

Maggie

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.