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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
damanpradhan
Helper I
Helper I

PowerBI REST API calls result in 403

Hi,


I am trying to call the PowerBi APIs using the PowerBI JS library.
I am successful in generating the id token and even go one step ahead and use the ADAL.acquireToken method to get an access token.
Post this, I try to access the APIs as mentioned in the documents.

However, I get a 403 with no details in the error object at all.
Stringify-ing the error shows the following: 

Error{"readyState":4,"responseText":"","status":403,"statusText":"Forbidden"}

 

I have the correct tenant and all the permissions granted to the App that I registered in Azure.
What should I be doing/what could be wrong in this case?

Can someone please help!

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @damanpradhan 

Here are similat links you could refer to

How to Generate Embed Token in pure JavaScript

JavaScript call API

 

Best Regards

Maggie

Thanks Maggie ! 

 

I had gone through these links before posting. They do not address specifically the scenario I am facing. 

I am still stuck with this problem and would appreciate any help.

damanpradhan
Helper I
Helper I

Just to clarify a few more things, I am using the PowerBI JS module installed through npm.

My current code looks like the following:

 

 

function userSignedIn(err, token) {
            if (!err) {
                var cachedToken = ADAL.getCachedToken(appid);
                if (!cachedToken) {
                    ADAL.acquireToken("https://analysis.windows.net/powerbi/api",
                        function(error, token) {
                            // Handle ADAL Error
                            if (error || !token) {
                                console.log('ADAL Error Occurred: ' + error);
                                return;
                            } else {
                                cachedToken = token;
                                console.log("Acquired access token...");
                            }
                        });
                }
                if (cachedToken) {
                    console.log('Token' + cachedToken);
                    $.ajax({
                        type: "GET",
                        url: "https://api.powerbi.com/v1.0/myorg/availableFeatures",//"dashboards",
                        headers: {
                            'Authorization': 'Bearer ' + cachedToken
                        }
                    }).done(function(data) {
                        console.log(data);
                    }).fail(function(err) {
                        console.log('Error' + JSON.stringify(err) );
                    }).always(function() {});
                };
            };
        }

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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