Redmineのチケット発行

qiita.com

powershell -ExecutionPolicy RemoteSigned-command  .\redmine_issue.ps1 `
-accessKey xxxx  `
-redmineUrl http://xxxxx.com `
-projectID XX `
-trackerID XX `
-title "XXX" `
-desc "XXX" `
-userId X  `
-watcherIdArray X,Y,Z
#引数定義
Param(
    [String]$accessKey,
    [String]$redmineUrl,
    [String]$projectID,
    [String]$trackerID,
    [String]$title,
    [String]$desc,
    [String]$userId,
    [array]$watcherIdArray,
)

#チケット発行URL
$postUri = $redmineUrl + "/issues.json"

# JSONパラメータ内容編集
$issue = @{
    project_id       = $projectID;                # プロジェクトID
    tracker_id       = $trackerID;                # トラッカーID(カテゴリ)
    subject          = $title;                    # タイトル
    description      = $desc.Replace("\r\n","`n") # 説明
    assigned_to_id   = $userId;                   # 担当者 ユーザID or グループID
    watcher_user_ids = $watcherIdArray;
}
$issueJson = @{issue = $issue; key = $accessKey}

# 書き換えたパラメータをjson形式に戻す
$postText = ConvertTo-Json $issueJson

#body部(json)変換
$postBody = [Text.Encoding]::UTF8.GetBytes($postText)

#REST API実行
$Redmine = Invoke-RestMethod -Method POST -Uri $postUri -Body $postBody -ContentType application/json