我试图从中获取信息的 API 是:https://avisi-apps.gitbook.io/tracket/api/worklog-api 它基本上以 JSON 格式返回员工所做的工作日志。
首先我必须得到一个 Bearer Token 来进行身份验证,这部分就完成了。
但是我还有另一个问题要分页到最后。
我基本上想要一种方法来获取所有页面,直到他没有下一个光标或下一个光标等于 null,这意味着这是最后一页。
我有一个错误阻碍了我,我想我已经做了大部分,但仍然遗漏了一点。
目前我只有 2 页我喜欢(图片)
实际结果
我这样做是因为我们在所有页面中都有一个游标 ID,除了最后一个页面,下一个游标等于 null。
这是我的代码:
Source = Json.Document(Web.Contents("https://v1-gateway-9e6mvodx.uk.gateway.dev/api/1.0/worklogs",[Headers = [#"Content-Type"="application/json", #"Authorization"=token]])),
#"Converted to Table" = Record.ToTable(Source),
#"Transposed to Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed to Table", [PromoteAllScalars=true]),
data = let
Pagination = List.Generate( ()=> Source,
each [worklogs] <> null,
each
if Record.HasFields(_, "next-cursor")
then Json.Document(Web.Contents("https://v1-gateway-9e6mvodx.uk.gateway.dev/api/1.0/worklogs?next=" & Text.From([#"next-cursor"]), [Headers=[Authorization=token]] ))
else
if [#"next-cursor"] = null
then Json.Document(Web.Contents("https://v1-gateway-9e6mvodx.uk.gateway.dev/api/1.0/worklogs", [Headers=[Authorization=token]] ))
else Record.FromList({null, null}, {"worklogs", "next-cursor"} ))
in
Pagination,
#"Converted to Table1" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Ignore),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table1", "Column1", {"worklogs", "next-cursor"}, {"worklogs", "next-cursor"})
in
#"Expanded Column1"
如果不清楚或您需要更多信息,请告诉我,
VB