Forum Discussion
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);
- Anonymous4 years ago
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:
400 Bad Request - HTTP | MDN (mozilla.org)
Regards,Xiaoxin Sheng
1 Reply
- AnonymousNot 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:
400 Bad Request - HTTP | MDN (mozilla.org)
Regards,Xiaoxin Sheng