Forum Discussion

mthierba's avatar
mthierba
Advocate I
9 years ago

Refresh Dataset API returns 400 Bad Request when refresh is in progress

Hi,

I'm making use of the new Dataset Refresh API, and the documentation states that a status code of 409 Conflict is returned when a refresh is already executing. However, I am receiving a 400 Bad Request for that exact scenario. I would prefer it if the implementation was matching the docs, hence if it was possible to distinguish the refresh-in-progress condition from any other generic API errors. Querying the Refresh History endpoint instead is not a viable alternative either because it only returns a status of "Unknown" when a refresh is in progress - again, making it impossible to distinguish that state from any other that might be deemed "unknown",

 

Thanks,

Mathias

7 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    mthierba wrote:

    Hi,

    I'm making use of the new Dataset Refresh API, and the documentation states that a status code of 409 Conflict is returned when a refresh is already executing. However, I am receiving a 400 Bad Request for that exact scenario. I would prefer it if the implementation was matching the docs, hence if it was possible to distinguish the refresh-in-progress condition from any other generic API errors. Querying the Refresh History endpoint instead is not a viable alternative either because it only returns a status of "Unknown" when a refresh is in progress - again, making it impossible to distinguish that state from any other that might be deemed "unknown",

     

    Thanks,

    Mathias


    mthierba

    Thanks for reporting that. I can reproduce the behavior of returning 400 while 409 is expected. I'm going to consulting this internally and as a workaround, you cound find the 400 error message to determine "refresh is executing".

     

     

            static void refreshDataset(string groupId, string datasetId)
            {
    
                HttpWebRequest request = System.Net.HttpWebRequest.CreateHttp(String.Format("https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/refreshes", groupId, datasetId));
                //POST web request to create a datasource.
                request.KeepAlive = true;
                request.Method = "POST";
                request.ContentLength = 0;
    
                //Add token to the request header
                request.Headers.Add("Authorization", String.Format("Bearer {0}", token));
    
                try
                {
                    //Write JSON byte[] into a Stream
                    using (Stream writer = request.GetRequestStream())
                    {
    
                        var response = (HttpWebResponse)request.GetResponse();
                        Console.WriteLine("Dataset refresh request {0}", response.StatusCode.ToString());
                    }
                }
                catch (WebException wex)
                {
                    if (wex.Response != null)
                    {
                        using (var errorResponse = (HttpWebResponse)wex.Response)
                        {
                            using (var reader = new StreamReader(errorResponse.GetResponseStream()))
                            {
                                string errorString = reader.ReadToEnd();
                                dynamic respJson = JsonConvert.DeserializeObject<dynamic>(errorString);
    //if refreshing is executing, the output would be "Invalid dataset refresh request. Another refresh request is already executing" Console.WriteLine(respJson["error"]["message"]); } } } } }

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    I am always getting the  "Operation returned an invalid status code 'UnsupportedMediaType'" error everytime I try to refresh a dataset. 

     

    Snippet

    var refreshData = client.Datasets.RefreshDatasetInGroup(cloneGroup.Id, report.DatasetId) as Datasets;
    • Eric_Zhang's avatar
      Eric_Zhang
      Microsoft Employee

      Anonymous wrote:

      I am always getting the  "Operation returned an invalid status code 'UnsupportedMediaType'" error everytime I try to refresh a dataset. 

       

      Snippet

      var refreshData = client.Datasets.RefreshDatasetInGroup(cloneGroup.Id, report.DatasetId) as Datasets;

      Anonymous

      What is the dataset in your case? What if you go with my demo calling REST API instead of using the SDK?

      • Anonymous's avatar
        Anonymous
        Not applicable

        Eric_Zhang I am getting "Invalid Dataset. This API can only be called on a Model-base dataset" when I use your demo.. Not sure what it means.