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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mrslyfox
Helper II
Helper II

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

Windows 2012R2 x64

PowerShell ISE

 

Script from PBI as is:

while($true){

$endpoint = "https://api.powerbi.com/beta/xxxxxxxx"

$payload = @{

"Measured" =123
"DateTime" =Get-Date -Format F
"MachineName" ="Test"
"TargetValue" =1672
"MinValue" =0
"MaxValue" =6000

}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
}

 

Return folowing error:

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:16 char:1
+ Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

What needs to be fixed ?

 

The same script working fine at Windows 10 Pro.

 

2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @mrslyfox,

 

Did you solve it? Can you share the answer or mark the proper answer as a solution please?

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @mrslyfox,

 

Since it works in Win 10, I would suggest:

1. Follow how-do-i-get-the-body-of-a-web-request-that-returned-400-bad-request-from-invoke to get more details of the error.

2. Check your code with the information in the Service.

Invoke_Rest_Method

3. A little possibility that caused by Firewall.

4. Upgrade the Power Shell.

 

Best Regards,

Dale

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.