我目前正在开发一个自定义数据连接器,该连接器调用一个安全 API 来实现 30 分钟后到期的可刷新 JWT。
此令牌被传递到数据 API 的标头。数据 API 通过将 URL 中的“page”变量增加 1 来进行分页。我在一个循环中实现了这一点,以在一个表中返回我的所有结果。
数据 API 调用确实在响应标头中返回了更新的令牌,但据我了解,出于安全原因,我无法使用 Value.Metadata 访问它。
我试图弄清楚如何刷新我的 JWT 或将其包含在我的分页循环中,以便在调用数据 API 时令牌不会过期。
此 API 不符合 OAuth 标准。
任何帮助将不胜感激。
section test_help;
[DataSource.Kind="test_help", Publish="test_help.Publish"]
shared test_help.Contents = (optional message as text) =>
//getPages function
let getPages = (Page as number) as table =>
//security API url
let url = "https://sapif.callminer.net/security/getToken",
//Authentication credentials passed to body of feapif
body = "{""Username"": ""fake"", ""Password"": ""fake"", ""ApiKey"": ""fake""}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
//endDate Variable to capture current date time in UTC
endDate = DateTimeZone.LocalNow(),
//date search GET Request
Host = "https://feapif.callminer.net/api/v2/export/datesearch",
//custom date search path with DateTimeZone.ToText for enddate and page parameter for pagination
//score ID 58 for MS and 55 for WC
Path = "?startDate=2021-05-01T12%3A00%3A00.000Z&stopDate="&DateTimeZone.ToText((endDate)) & "&page="& Number.ToText(Page) &"&records=50&clientCaptureDate=true&scoreIds=58,55",
Source = [
//JWT auth token passed to Data API header
token = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json; charset=utf-8"], Content = Text.ToBinary(body) ] )),
Source = Json.Document(Web.Contents(Host,
[RelativePath=Path,Headers=[#"Content-Type"="application/json; charset=utf-8", Authorization="JWT " & token]]))
],
Source1 = Source[Source],
#"Converted to Table" = Table.FromList(Source1, Splitter.SplitByNothing(), null, null, ExtraValues.Error) ,
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"RecordInfo", "Contact", "Attributes", "Measures", "Others", "Sections", "Categories", "Scores", "ScoreComponents"}, {"Column1.RecordInfo", "Column1.Contact", "Column1.Attributes", "Column1.Measures", "Column1.Others", "Column1.Sections", "Column1.Categories", "Column1.Scores", "Column1.ScoreComponents"}),
#"Expanded Column1.RecordInfo" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.RecordInfo", {"Id", "RowNumber", "TotalRowCount"}, {"Column1.RecordInfo.Id", "Column1.RecordInfo.RowNumber", "Column1.RecordInfo.TotalRowCount"})
in #"Expanded Column1.RecordInfo",
//Pagination loop
//Define function
Source = try List.Generate( ()=>
//try getPages (initialize page variable at 1), if records returned are not null increment page +1 if null stop. Convert list of records to table.
[Result = try getPages(1) otherwise null, Page = 1],
each [Result] <> null,
each [Result = try getPages([Page]+1) otherwise null, Page = [Page]+1],
each [Result]
)
otherwise {"1","null","null"},
//try catch block to capture empty lists/records
#"Converted to Table" = try Table.FromList(Source, Splitter.SplitByNothing(), 1, null, ExtraValues.Error) otherwise Table.FromList({"1"}, Splitter.SplitByNothing(), 1, null, ExtraValues.Error) ,
#"Expanded Column1" = Table.ExpandTableColumn(#"Converted to Table", "Column1", {"Column1.RecordInfo.Id", "Column1.RecordInfo.RowNumber", "Column1.RecordInfo.TotalRowCount", "Column1.Contact", "Column1.Attributes", "Column1.Measures", "Column1.Others", "Column1.Sections", "Column1.Categories", "Column1.Scores", "Column1.ScoreComponents"}, {"Column1.RecordInfo.Id", "Column1.RecordInfo.RowNumber", "Column1.RecordInfo.TotalRowCount", "Column1.Contact", "Column1.Attributes", "Column1.Measures", "Column1.Others", "Column1.Sections", "Column1.Categories", "Column1.Scores", "Column1.ScoreComponents"})
in #"Expanded Column1";