Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17881

JavaScript call API

$
0
0

I've tried to understand how everything works, registering apps etc. Autheticating with ADAL etc.

If anyone knows step by step, or have a sample where some JavaScript works, it woudl be helpful

 

I am trying to build an angular 2 app (but it can be pure javascript as well) to, embed on a webpage.

From that app I want to call  https://api.powerbi.com/v1.0/myorg/dashboards and auth with a token.

 

So since the app will be hosted at http://adress.com/somePage. Should I register an app with PowerBI, or not? Since I seem to need the clientId to get a token.

 

In this scenario I have logged in as myself and getting the cached token, to send to the API. 

 

This is some code I've tried, just trying to call it from localhost, but I get a 403:

    let token = this.adalService.getCachedToken(this.adalService.config.clientId);
    let headers = new Headers({
        'Authorization': 'Bearer ' + token,
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=utf-8',
    });
    let options = new RequestOptions({ headers: headers });


    return this.http.get(`https://api.powerbi.com/v1.0/myorg/dashboards`, options)
        .toPromise()
        .then((res) => { return res; })
        .catch((e) => { console.error(e); });

 

 


Viewing all articles
Browse latest Browse all 17881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>