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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Unable to create Dataset using PostDatasetInGroup API

When I tried to create dataset using the following request. It is giving bad request error. What is wrong with this request and how can I make it work.

 

 

var client = GetPowerBIClient();
var datasets = client.Datasets;
var table = new Table
{
Name = "Sample",
Columns = new List<Column>
{
new Column
{
Name = "Name",
DataType = "string"
},
new Column
{
Name = "Id",
DataType = "Int64"
},
new Column
{
Name = "Type",
DataType = "string"
}
}
};

var request = new CreateDatasetRequest();
request.Name = "SampleDataSet";
request.Tables = new List<Table> { table };
var gateway = client.Gateways.GetGateways().Value.FirstOrDefault();
var credentials = new BasicCredentials("Username", "Password");
var credentialsEncryptor = new AsymmetricKeyEncryptor(gateway.PublicKey);
var credentialDetails = new CredentialDetails(credentials, PrivacyLevel.Private, EncryptedConnection.Encrypted, credentialsEncryptor);
var datasource = client.Gateways.GetDatasources(gateway.Id).Value.FirstOrDefault(d => d.DatasourceName == "Sample1");
request.Datasources = new List<Datasource>
{
new Datasource
{
Name = datasource.DatasourceName,
ConnectionDetails = new DatasourceConnectionDetails
{
Database = "databasename",
Server = "servername"
},
DatasourceType = "Sql",
DatasourceId = datasource.Id,
GatewayId = gateway.Id,
ConnectionString = "Server=servername;Database=databasename;User ID=userId;Password=Password;"

}
};

var response = datasets.PostDatasetInGroup(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"), request);

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Anonymous,

According to the error message, it seems like they are something wrong with your HTTP request.

For this scenario, I'd like to suggest you take a look at the official document and push your dataset with the corresponding JSON format:

Push Datasets - Datasets PostDatasetInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Doc...

400 Bad Request - HTTP | MDN (mozilla.org)
Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

HI @Anonymous,

According to the error message, it seems like they are something wrong with your HTTP request.

For this scenario, I'd like to suggest you take a look at the official document and push your dataset with the corresponding JSON format:

Push Datasets - Datasets PostDatasetInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Doc...

400 Bad Request - HTTP | MDN (mozilla.org)
Regards,

Xiaoxin Sheng

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors