Power BI REST API错误请求措施

时间:2019-11-15 12:03:51

标签: powerbi

我创建的数据集没有大的发生率

{\"tableName\": \"Sales\"
,\"columns\": [ 
    {\"name\":\"ProductID\", \"dataType\":\"int64\", \"summarizeBy\":\"none\", \"isHidden\":\"True\", \"formatString\":\"#,##0\"}
    , {\"name\":\"Date\", \"dataType\":\"DateTime\", \"formatString\":\"dd/mm/yyyy\"}
    , {\"name\":\"TipID\", \"dataType\":\"int64\", \"summarizeBy\":\"none\", \"isHidden\":\"True\", \"formatString\":\"#,##0\"}
    , {\"name\":\"Sales\", \"dataType\":\"double\", \"formatString\":\"#,##0\"}
    ]
}

,但是当我尝试采取措施时,总会收到一个“ BadRequest”。

{\"tableName\": \"Sales\"
,\"columns\": [ 
    {\"name\":\"ProductID\", \"dataType\":\"int64\", \"summarizeBy\":\"none\", \"isHidden\":\"True\", \"formatString\":\"#,##0\"}
    , {\"name\":\"Date\", \"dataType\":\"DateTime\", \"formatString\":\"dd/mm/yyyy\"}
    , {\"name\":\"TipID\", \"dataType\":\"int64\", \"summarizeBy\":\"none\", \"isHidden\":\"True\", \"formatString\":\"#,##0\"}
    , {\"name\":\"Sales\", \"dataType\":\"double\", \"formatString\":\"#,##0\"}
    ]
    , \"measures\": [
        {\"name\": \"TrySales\", \"expression\": \"SUM(Sales[Sales])\"}
        ]
    }

我创建了一个“ Push Dataset”,其中仅添加了测量值,并且存在相同的错误。

        HttpContent body = new StringContent(postBody);
        body.Headers.ContentType = new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json");
        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Add("Accept", "application/json");
        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
        HttpResponseMessage response = client.PutAsync(restUri, body).Result;

JSON

{\"tableName\": \"Sales\"
, \"measures\": [
    {\"name\": \"TrySales\", \"expression\": \"CALCULATE(SUM(Ventas[Venta]);SUM(Sales[Sales])\"}
  ]
}

我仅找到示例代码in this link

PUT

的结果

标题

 {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Pragma: no-cache
  Transfer-Encoding: chunked
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Frame-Options: deny
  X-Content-Type-Options: nosniff
  RequestId: 6aa4198c-8315-4517-8f78-b5f90e6d1375
  Access-Control-Expose-Headers: RequestId
  request-redirected: true
  home-cluster-uri: https://wabi-europe-north-b-redirect.analysis.windows.net/
  Cache-Control: no-store, must-revalidate, no-cache
  Date: Fri, 15 Nov 2019 13:08:36 GMT
  Content-Type: application/json; charset=utf-8
}}

请求消息

 {Method: PUT, RequestUri: 'https://api.powerbi.com/v1.0/myorg/groups/1cd4f3cf-xxxx-41dd-83e4-c17708511d79/datasets/35b36723-ed24-xxxx-8e54-fc8e3a1503fe/tables/Sales'
, Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Accept: application/json
  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkJCOE...
  Content-Type: application/json
  Content-Length: 147
}}

有什么建议吗?

编辑 响应

Id = 37, Status = RanToCompletion
, Method = "{null}"
, Result = "{\"error\":{
    \"code\":\"BadRequest\"
    ,\"message\":\"Bad Request\"
    ,\"details\":[
        {\"message\":\"The property 'tableName' does not exist on type 'Microsoft.PowerBI.ServiceContracts.Api.Table'
        . Make sure to only use property names that are defined by the type.\"
        ,\"target\":\"tableSchema\"}
        ]
    }
    }

由于文档中的错误,似乎是拼写错误。在this link中,它显示为“ tableName”,我没有找到更多示例。

1 个答案:

答案 0 :(得分:0)

这是文档中的错误。 文档中的这个 example 在 json 中有 tableName。但是,当您点击 Try it 时,正文有 name

使用 name 而不是 tableName 对我有用。