Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create JIRA Issue with REST API via PowerShell Edited

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

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

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you