Skip to content

Instantly share code, notes, and snippets.

@cezarypiatek
Created March 23, 2023 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cezarypiatek/78cb352d4bb79fc8330ca558c3ce4942 to your computer and use it in GitHub Desktop.
Save cezarypiatek/78cb352d4bb79fc8330ca558c3ce4942 to your computer and use it in GitHub Desktop.
param (
[Parameter(Mandatory=$true)]
[string]$apiKey,
[Parameter(Mandatory=$true)]
[string]$issueKey,
[Parameter(Mandatory=$true)]
[string]$timeSpent,
[DateTime]$startDate = (Get-Date).Date
)
# Set up variables for JIRA API endpoint and the date in ISO-8601 format
$apiEndpoint = "https://your-jira-instance.com/rest/api/2/issue/"
$dateString = $startDate.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz")
# Set up authentication headers for JIRA
$headers = @{
"Authorization" = "Bearer $apiKey"
"Content-Type" = "application/json"
}
# Build the JSON payload for the JIRA API call
$json = @{
timeSpent = $timeSpent
started = $dateString
} | ConvertTo-Json
# Make the JIRA API call to report work time
$response = Invoke-RestMethod -Method POST -Uri ($apiEndpoint + $issueKey + "/worklog") -Headers $headers -Body $json
# Output the response from JIRA
$response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment