function ConvertTo-Base64($string) {
$bytes = [System.Text.Encoding]::UTF8.GetBytes($string);
$encoded = [System.Convert]::ToBase64String($bytes);
return $encoded;
}
$username = "***********"
$password = "***********"
function Get-HttpBasicHeader([string]$username, [string]$password, $Headers = @{}) {
$b64 = ConvertTo-Base64 "$($username):$($password)"
$Headers["Authorization"] = "Basic $b64"
$Headers["X-Atlassian-Token"] = "nocheck"
return $Headers
}
$restapiuri = "https://jira.<Organization>.mhc/rest/api/2/issue"
$headers = Get-HttpBasicHeader "user" "password"
#https://jira.<Organization>.mhc/projects/DEV/summary/rest/api/2/issue
$body = ('
{
"fields":
{
"project":
{
"id": "18400"
},
"summary": "Test",
"description": "Test",
"duedate": "2019-05-11",
"issuetype":
{
"id": "10002"
}
}
}')
Invoke-RestMethod -uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $body
I want to create a new issue in JIRA server not in cloud and I used this above script .
But it showing error like...."Invoke-RestMethod : The remote server returned an error: (401) Unauthorized".
It will be helpful ,if someone can help on this.