cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mthierba Frequent Visitor
Frequent Visitor

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 7
Highlighted
Moderator Eric_Zhang
Moderator

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


@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"]); } } } } }

 

nasar1588 Frequent Visitor
Frequent Visitor

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

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;
Moderator Eric_Zhang
Moderator

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


@nasar1588 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;

@nasar1588

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

nasar1588 Frequent Visitor
Frequent Visitor

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

@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.

Moderator Eric_Zhang
Moderator

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


@nasar1588 wrote:

@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.


@nasar1588

What is the datasource in your dataset?

hskrishna Frequent Visitor
Frequent Visitor

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

@nasar1588 @Eric_Zhang

 

I'm facing the same issue

 

Getting "Operation returned an invalid status code 'UnsupportedMediaType'" using the SDK as well as the REST API

 

@nasar1588 Were you able to resolve the issue?

hskrishna Frequent Visitor
Frequent Visitor

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

Update - Able to get it to work in Import mode. Earlier I was trying the refresh with DirectQuery. 

I guess Refresh for datasets in DirectQuery mode isn't supported.