Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Update Credentials C#

Hi,   following the instructions given in this post: http://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243   I ended up with the f...
  • Anonymous's avatar
    Anonymous
    8 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.