Web.Content调用API服务并将页面与List.Transform合并开始失败



我创建了PowerBI报告,该报告通过API服务连接到数据源。返回的json包含数千个实体。API服务是通过Web.Content函数调用的。API服务总是返回总记录数,因此我们能够计算需要调用的页面数量,以获得整个数据集。此报告显示来自我们的servicedesk应用程序的数据,该应用程序部署在许多服务器上,适用于许多客户,并使用Query参数连接到这些服务器中的任何一个。

Power查询的详细信息如下。

我为什么在这里写作。该报告在1.5年多的时间里一直没有任何问题,但在8月17日,其中一个服务器开始在步骤页面中引起错误,其中有一些随机的行(页面(有错误-见附图标记为";步骤Pages中的错误";。这就是查询中的下一步实体(List.Union(停止刷新并生成错误消息的原因:

  • Expression.Error:我们无法将字段访问应用于类型List。详细信息:值=[List]键=请求

什么是值得注意的

API服务si以相同的顺序返回记录,但当使用相同的参数调用时,错误列表是随机的
一些时间被刷新而没有任何错误

在另一台服务器上调用的相同电源查询工作正常,问题仅出在一台特定服务器上。

这个问题在最重要的服务器上开始时没有通知,1.5年后没有任何问题。

以下是该主源的全文查询功能,稍后将在其他查询中使用该功能来提取所有必要的数据。Json真的很复杂,我从中提取了请求列表、求解器列表、求解组列表,。。。。并且该基本查询及其输出是用于许多引用查询的输入。

步骤页面中的错误

let
BaseAPIUrl = apiurl&"apiservice?", /*apiurl is parameter - name of server e.g. https://xxxx.xxxxxx.sk/ */
EntitiesPerPage = RecordsPerPage, /*RecordsPerPage is parameter and defines nr. of record per page - we used as optimum 200-400 record per pages, but is working also with 4000 record per page*/
ApiToken = FnApiToken(), /*this function is returning apitoken value which is returning value of another api service apiurl&"api/auth/login", which  use username and password in body of call to get apitoken */
GetJson = (QParm) =>  /*definiton general function to get data from data source*/
let 
Options = 
[   Query= QParm,
Headers=
[
Accept="application/json", 
ApiKeyName="apitoken", 
Authorization=ApiToken
]
],
RawData = Web.Contents(BaseAPIUrl, Options),
Json    = Json.Document(RawData)
in  Json,
GetEntityCount = () =>  /*one times called function to get nr of records using GetJson, which is returned as a part of each call*/
let 
QParm = [pp="1", pg="1" ], 
Json  = GetJson(QParm),
Count = Json[totalRecord]
in  
Count,
GetPage = (Index) =>  /*repeatadly called function to get each page of json using GetJson*/
let 
PageNr  = Text.From(Index+1),
PerPage   = Text.From(EntitiesPerPage),
QParm = [pg = PageNr, pp=PerPage],
Json  = GetJson(QParm),
Value = Json[data][requests]
in  Value,
EntityCount = List.Max({ EntitiesPerPage, GetEntityCount() }),  /*setup of nr. of records to variable*/
PageCount   = Number.RoundUp(EntityCount / EntitiesPerPage),  /*setup of nr. of pages */
PageIndices = { 0 .. PageCount - 1 },
Pages       = List.Transform(PageIndices, each GetPage(_) /*Function.InvokeAfter(()=>GetPage(_),#duration(0,0,0,1))*/),  /*here we call for each page GetJson function to get whole dataset - there is in comment test with delay between getpages but was not neccessary*/
Entities    = List.Union(Pages),
Table       = Table.FromList(Entities, Splitter.SplitByNothing(), null, null, ExtraValues.Error)

我还尝试了另一种使用list.Genere将页面附加到列表中的方法与使用List.Transform的原始方式相比,它带来了转换到表的可能性,但其他引用的查询都失败了,并且在最后一行包含错误

当我通过添加为新查询来探索故障页面/列表的内容时,总是会有所有记录。。。。。

Source = List.Generate(    /*another way to generate list of all pages*/
()  =>  [Page = 0, ReqPageData = GetPage(0) ],
each [Page] < PageCount, 
each [ReqPageData = GetPage( [Page] ),
Page =  [Page] + 1 ], 
each [ReqPageData]
),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), /*here i am able to generate table from list in contrast when is used List.Generate*/
#"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"), /*here aj can expand list to column*/
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Expanded Column1", {"Column1"}) /*here i try to exclude errors, but i dont know what happend and which records (if any) are excluded*/

提取错误页面

最后,我完全不知道在这个特定的服务器上找不到这种行为的原因。我测试通过POSTMAN调用出错的页面,我与API服务的作者讨论了这个问题,他也尝试用所有参数调用这个API服务,但服务器正在返回每个页面OK,只有Power查询无法列出。转换…

如果有人在过去解决了同样的问题,我将不胜感激。。。。

Kuby

否,步骤list中列表的每个错误行。转换coud被提取为新查询,并且一页中有所有记录OK。hmmmm

Finnaly,本期中描述的问题是由";损坏的";返回json的内容。核心系统的提供商告诉我,他们发现了错误,在修复了服务磁盘后,一切都好了。我试图在电源查询中找到问题,但问题在服务磁盘中。:(

最新更新