Hope someone can help.
I'm trying to send a REST POST message using the Invoke-Rest method command to a sms service. When I use postman to send the request I'm able to send the message. However, when I try to do it in powershell I keep getting the following error and I'm unable to figure it out:
Invoke-RestMethod : {"error":"Validation error"}
At C:\Users\MTROTT\OneDrive - Volvo Cars\Projects\SMS API\mike.ps1:15 char:1
+ Invoke-RestMethod -Uri "$url" -Method Post -Body $mike -ContentType " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I'm using the below code:
$url = "https://1234.com/api/send"
# Define the JSON body of the POST request
$body_json = [ordered]@{
"apikey" = "KEY"
"from" = "FRNR"
"to" = "TONR"
"message" = "test"
"twoway" = "false"
"conversation" = "CONV123"
"checknumber" = "true"
} | ConvertTo-Json
Invoke-RestMethod -Uri $url -Method Post -Body $body_json -ContentType "application/json"
Kinda new to this so I would appreciate any help I can get.
Let me know if you need more info8 :)
I've tried Invoke-Webrequest but still the same result.
{"error":"Validation error"}implies the request is reaching the API endpoint but it's returning a custom error message in the response body - possibly due to bad data. Without more detail about what the API expects it's hard to suggest what might be wrong with your request. If you have a workingcurl.execommand or similar please add the details of that to your question...