<?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 Re: 403 Error when trying to access REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/296908#M8740</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Not sure if I'm just missing something. Trying to get to know the REST API, and I can't get past a 403 error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is for the user to click sign in, and then to load a list of their datasets. Sample here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://dashbi-encore.azurewebsites.net" target="_blank"&gt;https://dashbi-encore.azurewebsites.net&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var ADAL = new AuthenticationContext({
    instance: 'https://login.microsoftonline.com/',
    tenant: 'common', 
    clientId: 'ee4d167d-3a52-4578-b2f6-fd6fb8efb84a', 
    redirectUri: 'https://dashbi-encore.azurewebsites.net',
    callback: userSignedIn,
    popUp: true
});

function signIn() {
    ADAL.login();
}

function userSignedIn(err, token) {
    console.log('userSignedIn called');
    if (!err) {

        showWelcomeMessage();

        var trythis = "Bearer " + token;
        var request = new XMLHttpRequest();

        request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');

        request.setRequestHeader('Authorization', trythis);

        request.onreadystatechange = function() {
            if (this.readyState === 4) {
                console.log('Status:', this.status);
                console.log('Body:', this.responseText);
            }
        };

        request.send();
    } else {
        console.error("error: " + err);
    }
}

function showWelcomeMessage() {
    var user = ADAL.getCachedUser();
    var divWelcome = document.getElementById('WelcomeMessage');
    divWelcome.innerHTML = "Welcome " + user.profile.name;
}&lt;/PRE&gt;
&lt;P&gt;I seem to do fine getting the token from AD - and I pass it through in the header of my API request as instructed - but it just won't take. I have correctly created my application and requested the proper permissions (tried via multiple different portals) .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;@Anonymous&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The 403 error is caused by calling the Power BI get datasets API with an id_token where an acess token is required. Per the &lt;A href="https://github.com/AzureAD/azure-activedirectory-library-for-js/blob/dev/lib/adal.js" target="_self"&gt;ADAL JS lib&lt;/A&gt;, to get the access token, you'll have to call ADAL.acquireToken function after login. So you'll need something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;showWelcomeMessage();

ADAL.acquireToken("&lt;STRONG&gt;https://analysis.windows.net/powerbi/api&lt;/STRONG&gt;",function(token){
 
  
		  var trythis = "Bearer " + token;

                  var request = new XMLHttpRequest();

                  request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');

                  request.setRequestHeader('Authorization', trythis);

                  request.onreadystatechange = function () {
                    if (this.readyState === 4) {
                      console.log('Status:', this.status);
                      console.log('Body:', this.responseText);
                    }
                  };

                  request.send();


});&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your question is actually related to Azure AD development, for further questions, I'd suggest you post in the dedicated &lt;A href="https://social.technet.microsoft.com/forums/azure/en-US/home?forum=windowsazureaditpro" target="_self"&gt;AAD forum&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Nov 2017 07:57:55 GMT</pubDate>
    <dc:creator>Eric_Zhang</dc:creator>
    <dc:date>2017-11-06T07:57:55Z</dc:date>
    <item>
      <title>403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/296324#M8721</link>
      <description>&lt;P&gt;Not sure if I'm just missing something. Trying to get to know the REST API, and I can't get past a 403 error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is for the user to click sign in, and then to load a list of their datasets. Sample here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://dashbi-encore.azurewebsites.net" target="_blank"&gt;https://dashbi-encore.azurewebsites.net&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var ADAL = new AuthenticationContext({
    instance: 'https://login.microsoftonline.com/',
    tenant: 'common', 
    clientId: 'ee4d167d-3a52-4578-b2f6-fd6fb8efb84a', 
    redirectUri: 'https://dashbi-encore.azurewebsites.net',
    callback: userSignedIn,
    popUp: true
});

function signIn() {
    ADAL.login();
}

function userSignedIn(err, token) {
    console.log('userSignedIn called');
    if (!err) {

        showWelcomeMessage();

        var trythis = "Bearer " + token;
        var request = new XMLHttpRequest();

        request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');

        request.setRequestHeader('Authorization', trythis);

        request.onreadystatechange = function() {
            if (this.readyState === 4) {
                console.log('Status:', this.status);
                console.log('Body:', this.responseText);
            }
        };

        request.send();
    } else {
        console.error("error: " + err);
    }
}

function showWelcomeMessage() {
    var user = ADAL.getCachedUser();
    var divWelcome = document.getElementById('WelcomeMessage');
    divWelcome.innerHTML = "Welcome " + user.profile.name;
}&lt;/PRE&gt;&lt;P&gt;I seem to do fine getting the token from AD - and I pass it through in the header of my API request as instructed - but it just won't take. I have correctly created my application and requested the proper permissions (tried via multiple different portals) .&lt;/P&gt;</description>
      <pubDate>Sat, 04 Nov 2017 03:36:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/296324#M8721</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-04T03:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: 403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/296908#M8740</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Not sure if I'm just missing something. Trying to get to know the REST API, and I can't get past a 403 error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is for the user to click sign in, and then to load a list of their datasets. Sample here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://dashbi-encore.azurewebsites.net" target="_blank"&gt;https://dashbi-encore.azurewebsites.net&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var ADAL = new AuthenticationContext({
    instance: 'https://login.microsoftonline.com/',
    tenant: 'common', 
    clientId: 'ee4d167d-3a52-4578-b2f6-fd6fb8efb84a', 
    redirectUri: 'https://dashbi-encore.azurewebsites.net',
    callback: userSignedIn,
    popUp: true
});

function signIn() {
    ADAL.login();
}

function userSignedIn(err, token) {
    console.log('userSignedIn called');
    if (!err) {

        showWelcomeMessage();

        var trythis = "Bearer " + token;
        var request = new XMLHttpRequest();

        request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');

        request.setRequestHeader('Authorization', trythis);

        request.onreadystatechange = function() {
            if (this.readyState === 4) {
                console.log('Status:', this.status);
                console.log('Body:', this.responseText);
            }
        };

        request.send();
    } else {
        console.error("error: " + err);
    }
}

function showWelcomeMessage() {
    var user = ADAL.getCachedUser();
    var divWelcome = document.getElementById('WelcomeMessage');
    divWelcome.innerHTML = "Welcome " + user.profile.name;
}&lt;/PRE&gt;
&lt;P&gt;I seem to do fine getting the token from AD - and I pass it through in the header of my API request as instructed - but it just won't take. I have correctly created my application and requested the proper permissions (tried via multiple different portals) .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;@Anonymous&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The 403 error is caused by calling the Power BI get datasets API with an id_token where an acess token is required. Per the &lt;A href="https://github.com/AzureAD/azure-activedirectory-library-for-js/blob/dev/lib/adal.js" target="_self"&gt;ADAL JS lib&lt;/A&gt;, to get the access token, you'll have to call ADAL.acquireToken function after login. So you'll need something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;showWelcomeMessage();

ADAL.acquireToken("&lt;STRONG&gt;https://analysis.windows.net/powerbi/api&lt;/STRONG&gt;",function(token){
 
  
		  var trythis = "Bearer " + token;

                  var request = new XMLHttpRequest();

                  request.open('GET', 'https://api.powerbi.com/v1.0/myorg/datasets');

                  request.setRequestHeader('Authorization', trythis);

                  request.onreadystatechange = function () {
                    if (this.readyState === 4) {
                      console.log('Status:', this.status);
                      console.log('Body:', this.responseText);
                    }
                  };

                  request.send();


});&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your question is actually related to Azure AD development, for further questions, I'd suggest you post in the dedicated &lt;A href="https://social.technet.microsoft.com/forums/azure/en-US/home?forum=windowsazureaditpro" target="_self"&gt;AAD forum&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 07:57:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/296908#M8740</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-11-06T07:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: 403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/317422#M9391</link>
      <description>&lt;P&gt;@Anonymous&lt;/a&gt;, you managed to get this working?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 11:30:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/317422#M9391</guid>
      <dc:creator>Yaostha</dc:creator>
      <dc:date>2017-12-05T11:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: 403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/318590#M9409</link>
      <description>&lt;P&gt;Yes I did, but not on my own. I&amp;nbsp;ended up using this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi" target="_blank"&gt;https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And modifying it to request Power BI permissions/make Power BI API requests. I suggest anyone else having issues tries out this example before attempting their own implementation. I believe that the issue with my code was as suggested, not calling&amp;nbsp;&lt;SPAN&gt;ADAL.acquireToken.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 17:28:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/318590#M9409</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-12-06T17:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: 403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/320141#M9440</link>
      <description>&lt;P&gt;@Anonymous&lt;/a&gt;, Thanks for the response.&lt;/P&gt;&lt;P&gt;Will you be able to share the sample project for authenticating to powerbi?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 11:23:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/320141#M9440</guid>
      <dc:creator>Yaostha</dc:creator>
      <dc:date>2017-12-08T11:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: 403 Error when trying to access REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/320413#M9444</link>
      <description>&lt;P&gt;It's here right now, though I might take it down in the future.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://dashbi-encore.azurewebsites.net" target="_blank"&gt;https://dashbi-encore.azurewebsites.net&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log in, and then visit the "Todo list" tab. Watch the javascript console... you should see a list of your datasets appear.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 20:50:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/403-Error-when-trying-to-access-REST-API/m-p/320413#M9444</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-12-08T20:50:03Z</dc:date>
    </item>
  </channel>
</rss>

