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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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