Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Updating OAuth2 Dataset credentials via REST API

Hi All,


I'm running into a issue which is keeping me busy for quite a while now. My goal is to update datasource credentials via PowerShell. I'm now trying it via the REST API Tryout pane from MS. My Powershell Code runs into the exact same issue.

RemyBosman_0-1626437603689.png

Scenario:
Dataset with two connections: 1 connection to SharePoint, 1 connection to SQL.
Updating the SQL connections works fine, I'm using the basic request body as described here.

Performing the same update on the SharePoint connection with the OAUth2 body fails. Below the body i'm using (obviously with another accesstoken value. 
RemyBosman_0-1626436915230.png

I've tried several methods of retrieving the access token, and I have no idea what way of retrieving it is correct...
Method 1: Retrieving it via Get-PowerBIAccesToken 
Method 2: Via my registered App in SharePoint with FullControl permission on the corresponding site. 

RemyBosman_2-1626437162921.png

 

Error response is. Any help would be very much appreciated! 🙂
RemyBosman_3-1626437264714.png

 




 

4 REPLIES 4
Anonymous
Not applicable

Ok I figured this one out. It seems requesting an access token by 'grant_type' = 'password' does the job, while requesting it via 'grant_type' = 'client_credentials' doesn't.

 

Below the first scenario that works, the response includes a refresh token. 
The second scenario does not work. 

RemyBosman_0-1627022053297.png

RemyBosman_2-1627022122594.png

 

RemyBosman_1-1627022087119.png

RemyBosman_3-1627022140388.png

Anonymous
Not applicable

Hi Remy!

I'm having the same problem as you had, and still can'tseem to get a valid token to update the Sharepoint credential...

Could you go through all the steps you took to make it work? (Service Principal configuration and api permissions, any Sharepoint permission granting)... I'm literally running out of options to test this.

Thank you in advance.

Anonymous
Not applicable

Hi @Anonymous 

Your request is from this blog OAuth2 credentials example, it should be correct.

Rest API:

PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId}

Body:

{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"eyJ0....fwtQ\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}

Try steps as below to get the correct sharepoint access token.

For reference:

https://stackoverflow.com/questions/63321532/sharepoint-rest-api-how-to-get-access-token

https://anexinet.com/blog/getting-an-access-token-for-sharepoint-online/

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Anonymous
Not applicable

@RicoS Thanks for your reply. 
I've tried both scenario's (appregistration on SP and the App Registration in Azure AD). Both situations give me an access token. Both access tokens are not accepted by the request I'm sending to the endpoint below. 

PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId}

 
Is it possible for you to give it a try yourself? I'd really like to know if this is just me not being able to do this, or that the API is just not working properly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.