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

Power BI拼接URL自动更新报错:Web.Contents请求400错误

Power BI服务端调用API出现400错误排查求助

我在Power BI中有一个包含「PedidoId」列的查询,通过自定义函数利用该列生成URL调用API。本地测试时数据加载正常,但在Power BI服务端更新数据源凭据时出现400错误。API端点需要传入PedidoId数值,请求协助排查问题。

自定义函数代码

let
get_pedido_atendido = (pedidoId as number) =>
let
    baseUrl = "https://api.sienge.com.br/domainexemplo/public/api/v1/purchase-invoices/deliveries-attended?purchaseOrderId=",
    response = Web.Contents(
        baseUrl,
        [
            RelativePath = "",
            Query = [purchaseOrderId = Number.ToText(pedidoId)]
        ]
    ),
    json = Json.Document(response)
in
    json
in
get_pedido_atendido

错误信息

更新数据源凭据失败:Web.Contents 无法从 'https://api.sienge.com.br/domainexemplo/public/api/v1/purchase-invoices/deliveries-attended?purchaseOrderId=' 获取内容 (400): 错误请求(隐藏详情)
状态码:400
时间:2025年5月28日 星期三 14:27:40 GMT-0300(巴西标准时间)

问题分析与解决方案

问题出在Web.Contents的URL构造方式上:

  • 你的baseUrl已经包含了查询参数前缀?purchaseOrderId=,同时又通过Query参数再次传入purchaseOrderId,这会导致最终生成的URL出现重复参数,且Power BI服务端验证凭据时会尝试访问不带有效参数的URL,触发400错误。
  • Power BI服务端对Web.Contents的基础URL有严格要求,必须是固定静态地址,不能包含动态查询参数;本地环境对该限制更宽松,因此能正常运行。

修改代码如下:

let
get_pedido_atendido = (pedidoId as number) =>
let
    // 移除baseUrl中的查询参数部分,保留纯基础地址
    baseUrl = "https://api.sienge.com.br/domainexemplo/public/api/v1/purchase-invoices/deliveries-attended",
    response = Web.Contents(
        baseUrl,
        [
            RelativePath = "",
            Query = [purchaseOrderId = Number.ToText(pedidoId)]
        ]
    ),
    json = Json.Document(response)
in
    json
in
get_pedido_atendido

修改后,Web.Contents会自动将Query参数拼接为正确的URL格式,符合Power BI服务端要求,即可解决凭据更新时的400错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 23:50:58