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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
yangty152
Frequent Visitor

Issue to use Power Query to make a Post API call

I'm trying to follow a tutorial to make an API post call, but I cannot get it work. Can someone please help me check where I get it wrong? I removed the sensitive information but other than that, this is what I have, when I refresh, I recieve error below:

yangty152_0-1644009915093.png

 

let
body = "{""grant_type"":""password"",""resource"":""https://analysis.windows.net/powerbi/api"",""client_id"":"""",""username"":"""",""password"":"""",""client_secret"":""""}",
url = "https://login.microsoftonline.com/common/oauth2/token/",
Data = Web.Contents(
url,
[
Headers=[#"Content-Type" = "application/json; charset=utf-8"],
Content=Text.ToBinary(body)
]
),
response = Json.Document(Data)
in
response

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @yangty152 ,

 

The error is that the URL(https://login.microsoftonline.com/common/oauth2/token/) you entered only accepts POST, OPTIONS requests. But has received a GET request.

Eyelyn9_0-1644473391044.png

Refer to the syntax posted in this thread:

 //Resource Uri for Power BI API
            string resourceUri = "https://analysis.windows.net/powerbi/api";

            //OAuth2 authority Uri
            string authorityUri = "https://login.microsoftonline.com/common/";

            //Get access token:
            // To call a Power BI REST operation, create an instance of AuthenticationContext and call AcquireToken
            // AuthenticationContext is part of the Active Directory Authentication Library NuGet package
            // To install the Active Directory Authentication Library NuGet package in Visual Studio,
            //  run "Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory" from the nuget Package Manager Console.

            // AcquireToken will acquire an Azure access token
            // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
            AuthenticationContext authContext = new AuthenticationContext(authorityUri);
            var token = authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri)).Result.AccessToken;

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @yangty152 ,

 

The error is that the URL(https://login.microsoftonline.com/common/oauth2/token/) you entered only accepts POST, OPTIONS requests. But has received a GET request.

Eyelyn9_0-1644473391044.png

Refer to the syntax posted in this thread:

 //Resource Uri for Power BI API
            string resourceUri = "https://analysis.windows.net/powerbi/api";

            //OAuth2 authority Uri
            string authorityUri = "https://login.microsoftonline.com/common/";

            //Get access token:
            // To call a Power BI REST operation, create an instance of AuthenticationContext and call AcquireToken
            // AuthenticationContext is part of the Active Directory Authentication Library NuGet package
            // To install the Active Directory Authentication Library NuGet package in Visual Studio,
            //  run "Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory" from the nuget Package Manager Console.

            // AcquireToken will acquire an Azure access token
            // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
            AuthenticationContext authContext = new AuthenticationContext(authorityUri);
            var token = authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri)).Result.AccessToken;

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors