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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Set AzureBlob Datasource key using REST API

Hi,

 

I have a report which I embedded to my application using pbie.

the report itself have been embedded successfully, but the dataset cannot be refreshed.

after some checking, I know that the dataset doesn't have enough credentials to access my datasource, which are a csv file in Azure Blob storage.

Now, if I manually add my azure blob credentials to my datasets from power bi workspace it could be refreshed.

But, I want to automatically set my credentials from my application which are written in javascript.

 

I tried to use this API first to get my gateway and Datasource ID

 

GET https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/datasources

 

 it went well and I got the information perfectly.

 

next step, I wanted to update my datasource credentials information using this API

 

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

 

 with my OAuth token as my Authentication header, and request body like below:

 

{
	"credentialDetails": {
		"credentialType": "Key",
		"credentials": "{\"credentialData\":[{\"name\":\"key\", \"value\":\"MY KEY\"}]}",
		"encryptedConnection": "Encrypted",
		"encryptionAlgorithm": "None",
		"privacyLevel": "None"
	}
}

 

 

but it gave my 401 error with response :

 

{
  "error": {
    "code": "PowerBINotAuthorizedException",
    "pbi.error": {
      "code": "PowerBINotAuthorizedException",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}

 

 

can anybody give me a hint for where I done wrong?

or maybe if there are any other way to do this I would appriciate the infromation

 

bests,

2 REPLIES 2
asarraf21
Frequent Visitor

I am having the same issue, it is reported elsewhere too.

I think the core of the issue is that the PATCH endpoint does not work. My usecase was a BASIC user/pass to update datasource for Azure SQL server and it is throwing the same exception. This is my payload:

 

{
  "credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"admin\"},{\"name\":\"password\", \"value\":\"S3cretPasswrd\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "Private"
  }
}

 

The challenge is the exact same payload and endpoint works fine when you are logged in and run it interactively in the REST page. But when you get the token all through the REST api it throws an exception.

duartte23
New Member

Hi,

 

Did you get an answer to this issue?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.