<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Set AzureBlob Datasource key using REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/915010#M22137</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a report which I embedded to my application using pbie.&lt;/P&gt;&lt;P&gt;the report itself have been embedded successfully, but the dataset cannot be refreshed.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Now, if I manually add my azure blob credentials to my datasets from power bi workspace it could be refreshed.&lt;/P&gt;&lt;P&gt;But, I want to automatically set my credentials from my application which are written in javascript.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use this API first to get my gateway and Datasource ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;GET https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/datasources&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;it went well and I got the information perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;next step, I wanted to update my datasource credentials information using this API&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;with my OAuth token as my Authentication header, and request body like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"credentialDetails": {
		"credentialType": "Key",
		"credentials": "{\"credentialData\":[{\"name\":\"key\", \"value\":\"MY KEY\"}]}",
		"encryptedConnection": "Encrypted",
		"encryptionAlgorithm": "None",
		"privacyLevel": "None"
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it gave my 401 error with response :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "error": {
    "code": "PowerBINotAuthorizedException",
    "pbi.error": {
      "code": "PowerBINotAuthorizedException",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anybody give me a hint for where I done wrong?&lt;/P&gt;&lt;P&gt;or maybe if there are any other way to do this I would appriciate the infromation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bests,&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2020 00:27:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-01-30T00:27:01Z</dc:date>
    <item>
      <title>Set AzureBlob Datasource key using REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/915010#M22137</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a report which I embedded to my application using pbie.&lt;/P&gt;&lt;P&gt;the report itself have been embedded successfully, but the dataset cannot be refreshed.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Now, if I manually add my azure blob credentials to my datasets from power bi workspace it could be refreshed.&lt;/P&gt;&lt;P&gt;But, I want to automatically set my credentials from my application which are written in javascript.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use this API first to get my gateway and Datasource ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;GET https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/datasources&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;it went well and I got the information perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;next step, I wanted to update my datasource credentials information using this API&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PATCH https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;with my OAuth token as my Authentication header, and request body like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"credentialDetails": {
		"credentialType": "Key",
		"credentials": "{\"credentialData\":[{\"name\":\"key\", \"value\":\"MY KEY\"}]}",
		"encryptedConnection": "Encrypted",
		"encryptionAlgorithm": "None",
		"privacyLevel": "None"
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it gave my 401 error with response :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "error": {
    "code": "PowerBINotAuthorizedException",
    "pbi.error": {
      "code": "PowerBINotAuthorizedException",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anybody give me a hint for where I done wrong?&lt;/P&gt;&lt;P&gt;or maybe if there are any other way to do this I would appriciate the infromation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bests,&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 00:27:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/915010#M22137</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-30T00:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Set AzureBlob Datasource key using REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/1315552#M25393</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you get an answer to this issue?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 18:12:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/1315552#M25393</guid>
      <dc:creator>duartte23</dc:creator>
      <dc:date>2020-08-21T18:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set AzureBlob Datasource key using REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/3045895#M40912</link>
      <description>&lt;P&gt;I am having the same issue, it is reported &lt;A href="https://community.powerbi.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2165740" target="_self"&gt;elsewhere&lt;/A&gt; too.&lt;/P&gt;&lt;P&gt;I think the core of the issue is that the &lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource" target="_self"&gt;PATCH endpoint&lt;/A&gt; 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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{\"credentialData\":[{\"name\":\"username\", \"value\":\"admin\"},{\"name\":\"password\", \"value\":\"S3cretPasswrd\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "Private"
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenge is the exact same payload and endpoint works fine when you are logged in and run it interactively in the &lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource" target="_self"&gt;REST&lt;/A&gt; page. But when you get the token all through the REST api it throws an exception.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2023 18:45:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Set-AzureBlob-Datasource-key-using-REST-API/m-p/3045895#M40912</guid>
      <dc:creator>asarraf21</dc:creator>
      <dc:date>2023-01-26T18:45:10Z</dc:date>
    </item>
  </channel>
</rss>

