在Power Bi查询函数中进行POST REST API调用以生成令牌,并使用基于JWT的令牌进行另一个GET API调用

阿迪亚(Aditya Bhattacharya)

我需要使用Power Bi查询函数进行POST REST API调用以获取JWT访问令牌。然后使用获得的相同令牌进行GET API调用,以获取必须在Power Bi仪表板中显示的数据。

现在的问题是,我无法正确地获得访问令牌。我需要将客户端ID,客户端机密和资源uri作为POST API的主体进行传递,以获取令牌。

谁能帮我这个?

阿迪亚(Aditya Bhattacharya)

这最终对我起作用:

let

    GetJson = Web.Contents("https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/oauth2/token",
        [
            Headers = [# "Accept" = "application/json",
                # "Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
            ],
            Content = Text.ToBinary("client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&client_secret=xx***xx:/xxx?***&resource=api://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&grant_type=client_credentials")
        ]
    ),
    FormatAsJson = Json.Document(GetJson),
    # "Converted to Table" = Record.ToTable(FormatAsJson),
    # "Expanded Value" = Table.Last(# "Converted to Table"),
    access_token = List.Last(Record.FieldValues(# "Expanded Value")),
    source = Json.Document(Web.Contents("https://my-web-api.azurewebsites.net/api/get_my_data?Num=100", [Headers = [ContentType = "application/json"]])),
    Result = Json.Document(source)
    in
    # "Result"

请更新所需的凭据/机密/ ID或任何相关字段以使此工作正常进行。但是我会要求Microsoft或任何Microsoft附属的Power Bi Developer创建关于这些主题的更全面的文章或文档。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章