Forum Discussion
Update Credentials C#
- Anonymous8 years ago
I have found out that the BadRequest was already in the GetGatewayByIdWithHttpMessagesAsync call. But nevertheless I found an easier way to handle the problem:
var request = new HttpRequestMessage ( new HttpMethod ("PATCH"), $"https://api.powerbi.com/v1.0/myorg/gateways/{gatewayDatasource.GatewayId}/datasources/{gatewayDatasource.Id}"); request.Content = new StringContent ( $@" {{ 'credentialType': 'Basic', 'basicCredentials': {{ 'username': '{username}', 'password': '{password}' }} }}"); request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse ("application/json"); await m_powerBIClient.Credentials.ProcessHttpRequestAsync (request, cancellationToken);No nasty encryption as it is a secure connection anyway. Wondering why basic credentials are not supported by the C# API.
I have found out that the BadRequest was already in the GetGatewayByIdWithHttpMessagesAsync call. But nevertheless I found an easier way to handle the problem:
var request = new HttpRequestMessage (
new HttpMethod ("PATCH"),
$"https://api.powerbi.com/v1.0/myorg/gateways/{gatewayDatasource.GatewayId}/datasources/{gatewayDatasource.Id}");
request.Content = new StringContent (
$@" {{
'credentialType': 'Basic',
'basicCredentials': {{
'username': '{username}',
'password': '{password}'
}}
}}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse ("application/json");
await m_powerBIClient.Credentials.ProcessHttpRequestAsync (request, cancellationToken);
No nasty encryption as it is a secure connection anyway. Wondering why basic credentials are not supported by the C# API.
There is currently some issue with V2 client.Gateways.UpdateDatasourceAsync
The body which is sent using that method:
{
"credentialDetails": {
"credentials": "{\"credentialType\":\"Basic\",\"basicCredentials\":{\"username\":\"usrnmame\",\"password\":\"password\"}}"
}
}where the correct one should be:
{
"credentialType":"Basic",
"basicCredentials":{"username":"usrname","password":"password"}
}Simple http request as pointed above will work just fine:)