1

I want to invoke PowerBI rest api calls to upload pbix files from local/specific repository.

  • How should I generate bearer token for authorization from Postman?

  • Will this rest api call work to generateToken?

  • What needs to passed as authorization token for this rest call?

  • Does myorg is the PowerBI account name? from where can I fetch the myorg value?

     POST https://api.powerbi.com/v1.0/myorg/GenerateToken
    

Below are few more calls that I want to invoke through postman:

GET https://api.powerbi.com/v1.0/myorg/imports
GET https://api.powerbi.com/v1.0/myorg/reports/{reportId}

and few post calls also.

What will be a quick solution for generating token?

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Amruta
  • 701
  • 4
  • 15
  • 38

1 Answers1

0

You can use this function to request access

it is necessary to create the Client ID in azure https://learn.microsoft.com/en-us/power-bi/developer/embedded/register-app?tabs=customers%2CAzure

    application_id= 'None'
    application_secret= 'None'
    user_id= 'None'
    user_password= 'None'

    accessToken = None 
    requestHeaders = None 
    tokenExpiry = None 
    accessToken_AD = None 
    requestHeaders_AD = None 
    tokenExpiry_AD = None 

     def pbi_auth(application_id,application_secret,user_id,user_password):
        global accessToken
        global requestHeaders
        global tokenExpiry
        data = {
            'grant_type': 'password',
            'scope': 'openid',
            'resource': "https://analysis.windows.net/powerbi/api",
            'client_id': application_id,
            'client_secret': application_secret,
            'username': user_id,
            'password': user_password
        }
        token = requests.post("https://login.microsoftonline.com/common/oauth2/token", data=data)
        assert token.status_code == 200, "Fail to retrieve token: {}".format(token.text)
        #print("Got access token: ")
        #print(token.json())
        accessToken = token.json()['access_token']
    
        requestHeaders= {
            'Content-Type': 'application/json; charset=utf-8',
            'Authorization': "Bearer {}".format(accessToken)
        }

    pbi_auth(application_id,application_secret,user_id,user_password)
    reportId= ""
    URI = "https://api.powerbi.com/v1.0/myorg/reports/{}".format(reportId)
    queryResults =  requests.get(URI, headers=requestHeaders)
Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42
Wilson
  • 1
  • 1