Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mthierba
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
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;


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

 

@Anonymous Were you able to resolve the issue?

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.

 

 

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.


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


@Anonymous

What is the datasource in your dataset?

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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.