Forum Discussion
Possible to update credentials via REST API?
- 9 years ago
@v-lvzhan-msft wrote:I've voted for your idea.
Before I acutally did some research and thought I was close as I find this api Set Credentials. The datasource_id and gateway_id can be found via calling Get BoundGatewayDatasources. However when calling the Set Credential API, I've stuck by a "DMTS_InvalidEncryptionAlgorithmError" error. I'm going to escalate this internally and will post back if there comes any update.
By the way, I don't find any API to create a data source for a dataset in a gateway, even though above two APIs work, We still need such an API otherwise we may have to configure the datasource manually.
Here's the update from the Product team. The SET Credential API is for cloud datasources.
Based on my test, I can set credential with the API when the dataset is connecting to a Azure SQL database.
to get the Datasource and gateway id the user should use this API:
GET https://api.powerbi.com/v1.0/myorg/datasets/{dataset_id}/Default.GetBoundGatewayDataSources
and then to use the set credentials API.
PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gateway_id}/datasources/{datasource_id}
I thought the gateway_id in the PATCH API was an real gateway. While I got the declarification that It's not a real GW in this case, but this is what the API refers to.
So if you're using SQL Azure database, then I think you can obfuscate the data source credentials from the end-user.
TedPattison - interesting. Your code makes it seem as though you're just using the same exact call to update "Gateway" credentials for datasets. Any idea.. is this strictly limited to DirectQuery still? I'm hoping to use something similar for an Azure Analysis Services live connection.
I have used this code with imported datasets in Power BI as well as datasets that use DirectQuery against a Azure SQL database. When you have an imported dataset, you do not need to patch the data source credentials to make thing work at first because the data has already been imported into the Power BI cloud. Therefore, you only need to patch credentials for an imported datasets if you want to be able to refresh the dataset on demand or to schedule data refresh inside the Power BI service. DirectQuery datasets do not have imported data so you have to patch credentials for them to work at all.
This code was a bit confusing to me at first because you have to create a new GatewayDatasource object even when you are accessing an Azure SQL database without going through a Power BI Gateway.
My understanding is that this programming technique is also supposed to be used for datasets based on a live connections to a tabular database in Azure Ana;ysis Service. However, I have never tested it myself so I don't want to say it works until I have seen it work with my own eyes. I would love to hear from anyone in the Power BI community that has patched credentials to a Azure Analysis Services database.
- Eric_Zhang9 years agoMicrosoft Employee
Just have you two synced up.
I think your code is for Power BI Embedded while I think malagari is looking for the REST API for Power BI Service.
- malagari9 years agoContinued Contributor
Eric_Zhang is correct, I am looking at the Power BI.com API, not the PBI Embedded API. While TedPattison's code doesn't answer my question directly, it does provide some insight into the classes under-the-hood.
I'm going to spend a little bit of time poking around either way.