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

C#调用Power BI BindToGateway API报错:datasourceObjectIds需为列表

Power BI Semantic Model绑定网关API调用失败:datasourceObjectIds需为列表类型

问题核心在于datasourceObjectIds的参数类型不符合API要求。Power BI的BindToGateway接口要求该参数是Guid列表(IList),但你的代码里将其赋值为单个Guid对象,导致JSON序列化后变成单个字符串,无法匹配接口的参数格式,因此触发了类型转换错误。

修正后的代码

public static void BindGatewaytoDataset(string groupId, string datasetId, string bearer)
{
    var client = new RestClient($"https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/Default.BindToGateway");
    var request = new RestRequest(Method.POST);

    request.AddHeader("Content-Type", "application/json");
    request.AddHeader("Authorization", "Bearer " + bearer);

    var gatewayObjectID = new Guid("GATEWAYOBJECTID");
    // 将单个Guid替换为Guid列表,匹配API参数要求
    var datasourceObjectIds = new List<Guid> { new Guid("DATASOURCE") };

    request.AddJsonBody(new
    {
        gatewayObjectId = gatewayObjectID,
        datasourceObjectIds = datasourceObjectIds
        
    });

    IRestResponse response = client.Execute(request);

    if (response.IsSuccessful)
    {
        Console.WriteLine("网关已成功绑定到数据集。");
    }
    else
    {
        Console.WriteLine($"绑定网关到数据集失败: {response.StatusCode}");
    }
}

错误信息中文翻译

{"error":{"code":"BadRequest","message":"错误请求","details":[{"message":"无法将值"DATASOURCEGUID"转换为类型'System.Collections.Generic.IList`1[System.Guid]'。路径'datasourceObjectIds',第1行,位置118。","target":"bindToGatewayRequest.datasourceObjectIds"}]}}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 13:54:57