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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Markzolotoy
Impactful Individual
Impactful Individual

Keep getting 400 error

I have a working API that when I hit from Query keeps returning 400 error no matter what I do. I understand that without showing API documentation which I dont have it might be hard to help but still I am asking for help. Here are some relevant details fom Postman.

Markzolotoy_0-1615203894331.png

Markzolotoy_1-1615203991193.png

My code:

 

 

api_url = "https://localhost:446/token",
body = "{ ""client_id"": ""xxxxxx"",  ""username"": ""bba85b3d-5121-4439-8f3f-4c1a644bea5f"",  
         ""client_secret"": ""xxxxxxxxxxxxxxxxxx"", ""grant_type"": ""password""}",
    
    EncodedCredentials = Text.ToBinary(body),
    
    Token_Response  = Json.Document(Web.Contents(api_url,
    [ 
      Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
      Content=EncodedCredentials
    ]
    )
    )

 

 

No matter what I do, I get 400 back. In Postman misspelled parameters will generate an error message that comes back, but from PI I get nothing, just 400. Please help, I am stuck at this point.

 

Thanks

1 ACCEPTED SOLUTION
Markzolotoy
Impactful Individual
Impactful Individual

Finally figured it out. Here is how I am preparing parameters:

Text.ToBinary(Uri.BuildQueryString(body))

After that the backend gets proper parameters.

View solution in original post

2 REPLIES 2
Markzolotoy
Impactful Individual
Impactful Individual

Finally figured it out. Here is how I am preparing parameters:

Text.ToBinary(Uri.BuildQueryString(body))

After that the backend gets proper parameters.

Markzolotoy
Impactful Individual
Impactful Individual

I finally was able to put a break point into API's code. What happens is that no parameters are available in the code. So, what exaclty is not working? Does Query actually send parameters?

 

I am using OAuth. Here is the funtion:

public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)

 

conetxt is where I am checking for parameters. What I see is this:

Markzolotoy_0-1615230835633.png

when the same is called from Postman Results View has all the parameters.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.