Forum Discussion
Problem with Refreshing Dataset after Parameter Change with Service Principal
Hey LJonesStripe and jbauti10 , apology for the super late response on this.
I managed to find the solution to this using the following process:
- Create a gateway, and save its gateway_id.
- Take over the dataset from the original user to Service Principal. The Service Principal must the dataset owner to update the parameter. (POST endpoint)
- Update the parameter of the dataset (POST endpoint)
- Get the data source from the dataset, and retrieve its [gatewayId] (GET endpoint)
- If the gateway_id from step #1 is not the same as that from step #4, run this POST endpoint to bind the gateway. <--- For some reason this is required. Not sure why yet.
- Refresh the dataset to apply the parameter change to the dataset. (POST endpoint)
Let me know if it works on your end.
Hi fxs7576_02, thanks for your response!
Unfortunately, it still doesn't work for me. My datasource is PostgreSQL on Azure. I don’t currently have any gateways set up in Power BI Service, since I assumed for cloud Postgres no gateway is needed, but I’m not sure if that’s wrong.
Here's my process until now:
1. Get access token for service principal (I use the msal python library for this like in this example).
2. Take over dataset with this endpoint (POST endpoint).
3. Get gateway ID and datasource ID from the get datasource in group endpoint (GET endpoint)
4. Update the parameters of the dataset (POST endpoint)
5. Update datasource credentials (POST endpoint) using the gateway ID and datasource ID I get after taking over the dataset. I include this step because when the refresh is triggered I get an error saying: "It looks like scheduled refresh failed because at least one data source is missing credentials. To start the refresh again, go to this dataset's settings page and enter credentials for all data sources".
6. Refresh the dataset to apply the parameter changes. (POST endpoint)
The issue happens at step 5, I keep getting either:
{"error":{"code":"InvalidRequest","message":"The given connection details for selector # are invalid"}}or
{"error":{"code":"ItemNotFound","message":"Dataset doesn't contain a datasource that matches selector #1"}}
In the update datasource credentials step. The two body requests I've been using are the following:
body = {
"updateDetails": [
{
"datasourceSelector": {
"datasourceType": "PostgreSql",
"connectionDetails": {
"server": settings.PG_AZURE_HOST,
"database": settings.PG_AZURE_DATABASE
},
"gatewayId": gatewayID,
"datasourceId": datasourceID
},
"connectionDetails": {
"server": settings.PG_AZURE_HOST,
"database": settings.PG_AZURE_DATABASE
},
"credentialDetails": {
"credentialType": "Basic",
"credentials": json.dumps({
"username": settings.PG_AZURE_USER,
"password": settings.PG_AZURE_PASSWORD
}),
"encryptedConnection": "Encrypted",
"privacyLevel": "Private"
}
}
]
}or
body = {
"updateDetails": [
{
"datasourceSelector": {
"dataSourceType": "PostgreSQL",
"gatewayId": gatewayID,
"datasourceId": datasourceID
},
"connectionDetails": {
"server": settings.PG_AZURE_HOST,
"database": settings.PG_AZURE_DATABASE
},
"credentialDetails": {
"credentialType": "Basic",
"credentials": json.dumps({
"username": settings.PG_AZURE_USER,
"password": settings.PG_AZURE_PASSWORD
}),
"encryptedConnection": "Encrypted",
"privacyLevel": "Private"
}
}
]
}but neither work.
Questions:
- For Azure Postgres, do I need to set up a gateway in Power BI Service for this API call to succeed?
- Is my datasourceSelector wrong (maybe I shouldn’t include datasourceType / connectionDetails)?
- Or is there something else I’m missing in the credential update step?
Any kind of help is hugely appreciated!
Thanks.