You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power BI Power Query JSON请求负载格式无效问题求助

解决方案

错误原因分析

  1. 登录请求的用户名、密码等参数被错误放在请求头中,这类身份验证参数应作为JSON请求体传递。
  2. 手动拼接JSON字符串易出现格式错误(如换行、引号未正确转义),这是触发"Payload in a json request with invalid format"提示的核心原因。
  3. 使用Web.Contents时,指定Content参数会自动将请求方法设为POST,无需刻意声明GET(若接口实际要求传递请求体,本质就是POST请求)。

修复后的完整代码

let
    // 登录请求:参数放入请求体而非请求头
    URL1 = "example/login",
    LoginBody = Json.FromValue([
        Token = "TOKEN HERE",
        Appkey = "APPKEY HERE",
        Username = "USER HERE",
        Password = "PASS HERE"
    ]),
    Resposta = Web.Contents(
        URL1,
        [
            Headers = [#"Content-Type" = "application/json"],
            Content = LoginBody
        ]
    ),
    Fonte1 = Json.Document(Resposta),
    BearerToken = Fonte1[bearerToken],

    // 数据请求:用Record定义JSON结构,自动生成规范格式
    RequestBody = Json.FromValue([
        serviceName = "example.loadRecords",
        requestBody = [
            dataSet = [
                rootEntity = "example",
                includePresentationFields = "S",
                offsetPage = "0",
                criteria = [
                    expression = [
                        "$" = "(this.example= ? )"
                    ],
                    parameter = [
                        "$" = "01/08/2023",
                        type = "D"
                    ]
                ],
                entity = [
                    fieldset = [
                        list = "example,example,example,example,example,example,example"
                    ]
                ]
            ]
        ]
    ]),

    URL2 = "example/gateway/v1/example/example.sbr?example=example.example&outputType=json",
    RequestResponse = Web.Contents(
        URL2,
        [
            Headers = [
                #"Content-Type" = "application/json",
                Authorization = "Bearer " & BearerToken
            ],
            Content = RequestBody
        ]
    ),

    Fonte2 = Json.Document(RequestResponse),
    Table1 = Record.ToTable(Fonte2)
in 
Table1

关键修复点说明

  • 登录请求修正:把Token/Appkey等参数从请求头移到LoginBody,通过Json.FromValue将Record转换为标准JSON二进制数据,避免手动拼接失误。
  • 请求体生成优化:用Power Query的Record结构定义JSON内容,再由Json.FromValue自动生成符合语法规范的JSON,彻底解决手动字符串拼接导致的格式问题。
  • 请求方法适配:Web.Contents中指定Content后会默认使用POST方法,匹配接口需要传递请求体的实际需求。

内容的提问来源于stack exchange,提问作者webtristinho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 14:17:02