I am attempting to create a new FreshService ticket via PowerShell using API V2. I have successfully created a ticket via PowerShell using API V1. I have also successfully created a ticket via Curl using API V2. However, when creating a ticket via PowerShell using API V2, I get an Error 400 “Bad Request” notice. I have successfully run other API V2 commands via PowerShell.
Test code shown below. All specific data anonymised in **.
$APIKey = "*api-key*"
$EncodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $APIKey,$null)))
$HTTPHeaders = @{}
$HTTPHeaders.Add('Authorization', ("Basic {0}" -f $EncodedCredentials))
$HTTPHeaders.Add('Content-Type', 'application/json')
$URL = "https://*domain*.freshservice.com/api/v2/tickets"
$Attributes = @{}
$Attributes.Add('requester_id',*requesterID*)
$Attributes.Add('subject',"Test subject")
$Attributes.Add('description',"Test description")
$Attributes.Add('group_id',*groupID*)
$Attributes.Add('source',2)
$Attributes.Add('priority',1)
$JSON = $Attributes | ConvertTo-Json
$JSON
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $URL -Headers $HTTPHeaders -Body $JSON -Method Post
Error received
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:19 char:1
+ Invoke-RestMethod -Method POST -Uri $URL -Headers $HTTPHeaders -Body ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand