Hi,
I am trying to create new datasources under gateway using api from C# but still gets error response "400: Bad request".
Supplied credentials encrypted as described in https://msdn.microsoft.com/en-us/library/mt784645.aspx
Here's code i'm using...
string powerBIDatasourcesApiUrl = String.Format("https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources", gatewayId);
HttpWebRequest request = System.Net.WebRequest.Create(powerBIDatasourcesApiUrl) as System.Net.HttpWebRequest;
//POST web request to create a datasource.
request.KeepAlive = true;
request.Method = "POST";
request.ContentLength = 0;
request.ContentType = "application/json";
//Add token to the request header
request.Headers.Add("Authorization", String.Format("Bearer {0}", token));
string datasourceJson = "{" + "\"name\":\"" + <datasourceName> + "\"," + "\"type\":\"Sql\"," + "\"connectionDetails\":\"{\"server\":\"<server>\",\"database\":\"<database>\"}\"," + "\"credentialDetails\":{" + "\"credentials\":\"" + <credentialsHash> + "\"," + "\"encryptionAlgorithm\":\"RSA-OAEP\"," + "\"encryptedConnection\":\"Encrypted\"," + "\"privacyLevel\":\"Public\"," + "\"credentialType\":\"Windows\"" + "}}";
//POST web request
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(datasourceJson);
request.ContentLength = byteArray.Length;
//Write JSON byte[] into a Stream
using (Stream writer = request.GetRequestStream())
{
writer.Write(byteArray, 0, byteArray.Length);
writer.Flush();
writer.Close();
writer.Dispose();
var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(string.Format("Datasource {0}", response.StatusCode.ToString()));
}