Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi Folks,
I'm failing on pretty simple task - update datasource credentials with OAuth2 token passed in payload.
Firstly, i'm generating new token to be passed with below request:
$getDatasourceTokenRequestParams = @{
Method = 'POST'
Uri = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token"
Body = @{
grant_type = 'client_credentials'
client_id = $ClientId
client_secret = $ServicePrincipalSecret
scope = $ClientId+'/.default'
audience = 'https://s*****-test.database.windows.net/'
}
}
$TokenRequest = Invoke-RestMethod @getDatasourceTokenRequestParams
Then i paste this token into my request using Try It facility on
https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#code-try-0
I insert datasourceid and gatewayid and request body with the token:
{
"credentialDetails": {
"credentialType": "OAuth2",
"credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1yNS1BVWliZkJpaTdOZDFqQmViYXhib1hXMCJ9.eyJhdWQiOiI1ZjkwMGRhOC03NTUzLTQyYWItOTljYy1hM2QzNjg3ZTM3MzEiLCJpc3M
iOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vM2UyMGVjYjItOWNiMC00ZGYxLWFkN2ItOTE0ZTMxZGNkZGE0L3YyLjAiLCJpYXQiOjE2NDAyNjYyNDMsIm5iZiI6MTY0MDI2NjI0Myw
iZXhwIjoxNjQwMjcwMTQzLCJhaW8iOiJFMlpnWU5DLzhEak45UFBSOVNIOHhoYzRLODY5QWdBPSIsImF6cCI6IjVmOTAwZGE4LTc1NTMtNDJhYi05OWNjLWEzZDM2ODdlMzczMSIsImF6cGFjciI6IjE
iLCJvaWQiOiI3NjMxNmI5Zi0xYzA2LTQzZTItYTNkZi02NzQzMjk5OTUzZmQiLCJyaCI6IjAuQVJzQXN1d2dQckNjOFUydGU1Rk9NZHpkcEtnTmtGOVRkYXRDbWN5ajAyaC1OekViQUFBLiIsInN1YiI
6Ijc2MzE2YjlmLTFjMDYtNDNlMi1hM2RmLTY3NDMyOTk5NTNmZCIsInRpZCI6IjNlMjBlY2IyLTljYjAtNGRmMS1hZDdiLTkxNGUzMWRjZGRhNCIsInV0aSI6IAOI_EnwgM_-1TOcGHiXXPkQqLH5D9STh_KhgC0xgLBZV8W3eO5jMffUxRsuUIGeJigcGbeKlGLCj08k_OgbPeoyAPloGI_Ahl9x3FSE1G0kQH7ehP7wdlI
ppwL09Yi1ScId09NzZnJHtcvUOrOrqgE8oSSx3cn_BwvQnGB8UDTSEufig\"}]}",
"encryptedConnection": "Encrypted",
"encryptionAlgorithm": "None",
"privacyLevel": "None"
}
}
All looks great but i receiving 401 response code 😞
{
"error": {
"code": "PowerBINotAuthorizedException",
"pbi.error": {
"code": "PowerBINotAuthorizedException",
"parameters": {},
"details": [],
"exceptionCulprit": 1
}
}
}
I assume that token i generated is incorrect, but unfortunately i didn't found any documentation on how exactly it should be generated.
Could you please provide me with the steps how to get correct token for this request?
Hi @SashaSydorenko ,
Are you using service principal? If so, did you go through all the proper configuration to enable service principal access to Power BI API in your tenant and add servide principal as gatewway admin?
https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Liang,
Service Principal have ReadWrite scope API permissions. Not sure about gateway admin? It's some kind of role in Power BI tenant? I'm actually not using gateways because datasource is in Azure.
Did you grant that app/service principal the required gateway admin permissions and the ReadWrite scope on the tenant?
Hi lbendlin,
Service Principal have ReadWrite scope API permissions. Not sure about gateway admin? It's some kind of role in Power BI tenant? I'm actually not using gateways because datasource is in Azure.
Your original question stated "gateway datasource credentials". Please clarify.
Hmmm good point. 🙂
It a bit confusing because it is how docs article is called https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource
But yeah, my report don't need a gateway - datasourcse is Azure SQL DB.
Does i'm use wrong API to update datasource credentials in this case?
Didn't found any other way to do that.
Hi @SashaSydorenko ,
Did you manage to resolve this issue?
I am getting the same error.
Please share if you have a solution.
Thanks
User | Count |
---|---|
13 | |
5 | |
2 | |
1 | |
1 |
User | Count |
---|---|
24 | |
3 | |
3 | |
2 | |
2 |