使用电源查询(自定义连接器)访问API源的记录

发布于 2025-02-05 06:26:20 字数 2032 浏览 2 评论 0 原文

这是我在 JSON主体(不是标头)中的API分页 - 如何使用自定义连接器中的电源查询访问?

我已经为API构建了一个自定义连接器,该连接器将其分页数据发送回到体内响应,而不是标题。在GitHub自定义连接器中记录了使用GetNextLink使用标头的方法:

GetNextLink = (response, optional request) =>
    let
        // extract the "Link" header if it exists
        link = Value.Metadata(response)[Headers][#"Link"]?,
        links = Text.Split(link, ","),
        splitLinks = List.Transform(links, each Text.Split(Text.Trim(_), ";")),
        next = List.Select(splitLinks, each Text.Trim(_{1}) = "rel=""next"""),
        first = List.First(next),
        removedBrackets = Text.Range(first{0}, 1, Text.Length(first{0}) - 2)
    in
        try removedBrackets otherwise null;

从响应正文中获取分页数据应该比头部更容易,我学会了。但是我很难过。在图像中,您可以看到我想通过web.contents()

?我正在尝试获得上面的“下一个”记录。

GetNextLink = (response) =>
// response is data already run through Web.Contents()

let
   Source = Lines.FromBinary(response),
   nextPage = Record.Field(Source[paging], "next")
in 
   try nextPage otherwise null;

我会收回错误“我们无法将类型记录的值转换为键入文本”。我觉得我没有得到“正确的来源”?我当然可以使用帮助,因为我是一个PowerQuery Newbie!

谢谢!

This is a follow up to my issue at API Pagination in JSON Body (not Header) - How to Access with Power Query in Custom Connector?

I have built a custom connector for an API that sends its pagination data back in the body of the response, rather than the header. The way to use GetNextLink using header is documented in the GitHub custom connector example:

https://github.com/microsoft/DataConnectors/blob/master/samples/Github/github.pq

GetNextLink = (response, optional request) =>
    let
        // extract the "Link" header if it exists
        link = Value.Metadata(response)[Headers][#"Link"]?,
        links = Text.Split(link, ","),
        splitLinks = List.Transform(links, each Text.Split(Text.Trim(_), ";")),
        next = List.Select(splitLinks, each Text.Trim(_{1}) = "rel=""next"""),
        first = List.First(next),
        removedBrackets = Text.Range(first{0}, 1, Text.Length(first{0}) - 2)
    in
        try removedBrackets otherwise null;

Getting to the pagination data from the body of the response should be easier than the header, I've learned. But I am stumped. In the images, you can see the record I am trying to access that comes back through Web.Contents()

This is my code for the GetNextLink function. I am trying to get the "next" record above.

GetNextLink = (response) =>
// response is data already run through Web.Contents()

let
   Source = Lines.FromBinary(response),
   nextPage = Record.Field(Source[paging], "next")
in 
   try nextPage otherwise null;

I get the error back "We cannot convert a value of type Record to type Text". I feel like I am not getting the 'Source" correctly? I could certainly use help as I am a PowerQuery newbie!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2025-02-12 06:26:20
GetNextLink = (response) =>
// response is data already run through Web.Contents()
let Source = Lines.FromBinary(response),
nextpage = try Source[paging][next] otherwise null
in nextpage

GetNextLink = (response) =>
// response is data already run through Web.Contents()
let  Source = Lines.FromBinary(response)
nextpage = try Record.Field(Source[paging],"next") otherwise null
in nextpage

GetNextLink = (response) =>
// response is data already run through Web.Contents()
let Source = Lines.FromBinary(response),
nextpage = try Source[paging][next] otherwise null
in nextpage

or

GetNextLink = (response) =>
// response is data already run through Web.Contents()
let  Source = Lines.FromBinary(response)
nextpage = try Record.Field(Source[paging],"next") otherwise null
in nextpage

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文