Can't set ticket id when creating a new ticket via Powershell

Hi, i am trying to create a ticket via the v2 API on powershell. It has so far worked fine but if I add the ‘id’ attribute (because I want to set the ticket id so i can call it later) it returns code 400 like below:


$Attributes = @{}
$Attributes.Add('id',1000)
$Attributes.Add('workspace_id',2)
$Attributes.Add('subject',"[JIRA Migrated] imported from API 3")
$Attributes.Add('requester_id',22000134116)
$Attributes.Add('description',"Test description")
$Attributes.Add('status',2)
$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```


RESPONSE:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At C:\
+ Invoke-WebRequest -Uri $URL -Headers $HTTPHeaders -Body $JSON -Method ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExce 
   ption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand



Like i said i just want to preset the ticket id on creation. am i doing something wrong here? any suggestions? thanks.
1 Like

Hello @rlupi001, when creating a ticket the Ticket ID is a unique identifier of the ticket. It is not a property that can be set at the time of creation. Once the ticket is created, you can then reference the ticket ID that is assigned to the ticket and given back to you in your response payload. I admit that isn’t clear in the documentation.

Hope that helps. Take care :slight_smile:

1 Like