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
Anonymous
Not applicable

PostRows not working with package Microsoft.PowerBi.Api

I was able to get the rest APIs working quickly in C#. The code works fine without any errors or exceptions, but the PostRows ( ) method didn't seem to work.

 

The dataset, table, and columns get created fine, but the rows don't seem to get saved/loaded. I verify by going online to Power BI Service and using a table visualization and adding the table columns to it. It does not show the saved data - see screenshot.

 

Did the rows not save/load? or am I going to the wrong place to see the data?

Thank you for your help.

 

using package Microsoft.PowerBi.Api

 

 

var tableName = "test-table-1";
            var table = new Table()
            {
                Name = tableName,
                Columns = new List<Column>()
                {
                    new Column("col1", "string"),
                    new Column("col2", "string"),
                    new Column("col3", "string")
                }
            };
            var dataset = await PowerBiClient.Datasets.PostDatasetAsync(new CreateDatasetRequest()
            {
                Name = "test-dataset-1",
                DefaultMode = "Push",
                Tables = new List<Table>() {table}
            });
            var postRows = new PostRowsRequest
            {
                Rows = new List<object>()
                {
                    new
                    {
                        col1 = "sdsdds",
                        col2 = "rtetete",
                        col3 = "werwer2423"
                    },
                    new
                    {
                        col1 = "sd333sdds",
                        col2 = "rtet234ete",
                        col3 = "werw1111er"
                    }
                }
            };
            await PowerBiClient.Datasets.PostRowsAsync(dataset.Id, tableName, postRows);

 

 

Screenshot_2020-09-27 Power BI.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Further investigation revealed that the sdk doesn't handle serialization of anonymous types and silently blanks them out.

As an example, this can be overcome/verified by specifying serialization settings as below.

 

PowerBiClient.SerializationSettings.ContractResolver = new DefaultContractResolver(); //anonymous types serialize to blank {} without this
            await PowerBiClient.Datasets.PostRowsAsync(dataset.Id, tableName, postRows);

 

The sdk doesn't have great documentation - almost none actually.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Further investigation revealed that the sdk doesn't handle serialization of anonymous types and silently blanks them out.

As an example, this can be overcome/verified by specifying serialization settings as below.

 

PowerBiClient.SerializationSettings.ContractResolver = new DefaultContractResolver(); //anonymous types serialize to blank {} without this
            await PowerBiClient.Datasets.PostRowsAsync(dataset.Id, tableName, postRows);

 

The sdk doesn't have great documentation - almost none actually.

Anonymous
Not applicable

I was wondering why it was not working... seems like we have to go see the internal code.

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.

Top Solution Authors
Top Kudoed Authors