Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

programmatic data refresh using api

I have found that with the new PBI API there is an option to trigger a dataset refresh programatically.  I was looking at implementing this into a powershell script that could be called at the end of...
  • Anonymous's avatar
    Anonymous
    9 years ago

    Thanks for the response Eric_Zhang, it let me know that what I was trying to achieve could be done.  I did some more digging and was able to modify the function in the PS script to use supplied credentials:

     

    function GetAuthToken
    {
        $adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
     
        $adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
     
        [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
     
        [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
     
        $redirectUri = "https://login.live.com/oauth20_desktop.srf"
     
        $resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
     
        $authority = "https://login.windows.net/common/oauth2/authorize";
           
        $userName = "[email protected]"
    
        $password = "MyPW"
    
        $creds = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" -ArgumentList $userName,$password
     
        $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
    
        $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $creds)
       
    
        return $authResult
    
    }

    Obviously I won't be hardcoding these credentials in the script but for testing purposes it works!

     

    EDIT:  it looks like my code block has been invaded with emoji's.  If anyone is wondering you would replace the emoji with a colon ":" and the letter "P".