To replace the data sourced in Power BI via REST API, here’s what you should do:
- Get the Dataset ID: First of all, make sure you have the datasetId of the Power BI dataset which you want to change. You can achieve that by calling:
GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets
In this case, you need to replace the {groupId} with your workspace ID.
- Identify the Current Data Source: After obtaining the datasetId, verify the available data sources by invoking the following:
GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/datasources
A consequence of the preceding is that it generates the data sources tied to that particular dataset such as the one with the datasourceId that you would like to change.
- Datasource Updating: In case you wish to change the proposed datasourceId, do the following request and provide details regarding the new data source in the body:
PATCH https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/Default.UpdateDatasources
- Authentication: Always bear in mind that use of the Power BI REST API means use of OAuth 2.0. Make sure that the app has been granted the needed permissions (Dataset.ReadWrite.All) and a token has been received before attempting to make any requests.
These steps will assist you in successfully changing the datasourceId for a dataset present in Power BI.