Start a new topic

API (400) Bad request error

Hi I get this error with my powershell script. How can I fix so the request goes through? 

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

 Here's the script:

 

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 

$APIKey = 'K58O3NlKuIMP2ZFh7BtY'
$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://bcservices.freshservice.com/api/v2/tickets'

##########
$TicketAttributes = @{}
$TicketAttributes.Add('requester_id', '15000000000')
$TicketAttributes.Add('email', 'example_email@email.com')
$TicketAttributes.Add('phone', '555-555-5555')
$TicketAttributes.Add('status', '2')
$TicketAttributes.Add('priority', '2')
$TicketAttributes.Add('source', '2')
$TicketAttributes.Add('type', 'incident')
$TicketAttributes = @{'ticket' = $TicketAttributes}
$JSON = ($TicketAttributes | ConvertTo-Json) 

# Invoke the request
Invoke-RestMethod -Method POST -Uri $URL -Headers $HTTPHeaders -Body $JSON

 

Login or Signup to post a comment