Skip to content

Instantly share code, notes, and snippets.

@justaguywhocodes
Created April 16, 2025 12:09
Show Gist options
  • Save justaguywhocodes/081d9804fe6b9a7fadf44c4d88b521ab to your computer and use it in GitHub Desktop.
Save justaguywhocodes/081d9804fe6b9a7fadf44c4d88b521ab to your computer and use it in GitHub Desktop.
# Define variables
$jiraUrl = "https://your-domain.atlassian.net/rest/api/3/issue" # Replace with your Jira instance URL
$email = "[email protected]" # Replace with your Jira account email
$apiToken = "YOUR_API_TOKEN" # Replace with your Jira API token later
$projectKey = "PROJECT" # Replace with your Jira project key (e.g., "ABC")
$issueType = "Task" # Replace with desired issue type (e.g., "Bug", "Story", "Task")
$summary = "New ticket created via API" # Replace with ticket summary
$description = "This is a sample ticket created using the Jira REST API." # Replace with ticket description
# Create the authentication header
$authString = "$email`:$apiToken"
$encodedAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($authString))
$headers = @{
"Authorization" = "Basic $encodedAuth"
"Content-Type" = "application/json"
}
# Define the JSON payload for creating the issue
$body = @{
fields = @{
project = @{
key = $projectKey
}
summary = $summary
description = @{
type = "doc"
version = 1
content = @(
@{
type = "paragraph"
content = @(
@{
type = "text"
text = $description
}
)
}
)
}
issuetype = @{
name = $issueType
}
}
} | ConvertTo-Json -Depth 10
# Make the API request
try {
$response = Invoke-WebRequest -Uri $jiraUrl -Headers $headers -Method Post -Body $body -ErrorAction Stop
$responseContent = $response.Content | ConvertFrom-Json
Write-Host "Ticket created successfully! Issue Key: $($responseContent.key)"
}
catch {
Write-Host "Failed to create ticket: $($_.Exception.Message)"
Write-Host "Response: $($_.Exception.Response)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment