Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Create JIRA Issue with REST API via PowerShell

Deleted user May 03, 2019

I'm trying to create a JIRA issue via Powershell.

Here's my code.

function ConvertTo-Base64($string) {

$bytes = [System.Text.Encoding]::UTF8.GetBytes($string);
$encoded = [System.Convert]::ToBase64String($bytes); return $encoded;
} 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://baseurl/rest/api/2/issue/"
$headers = Get-HttpBasicHeader "user" "password"

= (' { "fields": { "project": { "id": "10402" }, "summary": "Test", "description": "Test", "duedate": "2019-05-11", "issuetype": { "id": "3" }, "reporter": { "name": "user" }, "priority": { "id": "10101" }, "customfield_11403": "Test", "security": { "id": "11213" }, "components": [ { "id": "10805" } ] } }') Invoke-RestMethod -uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $body

The JSON part of it runs fine as I've tried it using Postman and the issue got created.

In Powershell however, I always get a 400 bad request returned. Does anyone got any ideas why this might be?

The authentication also works because with the same code I'm able to add comments and retrieve filter details etc. I'm about to lose my mind. I just can't get this working.



2 answers

1 accepted

1 vote
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 07, 2019 • edited

Hello Marius,

Thank you for sending over your scripts along with the response code you’re receiving. From reviewing your script I noticed there was an additional slash (/) within your $restapiuri variable which may make PowerShell angry (sometimes).

Outside of this, the 400 response typically means there is a field missing or misrepresented within the JSON data. Since you reported it works within postman then this shouldn’t be the case. The next step we should take would be to see the actual response from the Invoke-restmethod. You’ll want to incorporate the usage of


within your Invoke-restmethod to have your actual response with error message stored for viewing later. Atop of this, you’ll also want to use a catch statement to ensure you’re able to view the error when they are triggered. Here are reference documents to help achieve this:

I hope this proves helpful in finding your actual response error with the message to find what the cause of the failure is.

Stephen Sifers

Deleted user May 08, 2019

Stephen, I was just moments away from pulling my hair out. I spent hours trying to find the issue and in the end, the slash was in fact the culprit......

Thank you so much for pointing that out! It now works! :D

Like Stephen Sifers likes this

What would be the code to 

Create JIRA Issue with REST API via PowerShell?

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events