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

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

Jira API - Passing powershell parameter

Please can someone confirm how to pass a parameter into the API URL using powershell.

I create a new Jira ticket via the API and store the response ticket ID as a powershell parameter called $jiraticketid

I then try add comment to the newly created ticket within the same powershell script, adding the ticket ID parameter into the API URL shown below in bold:

$body = "
`n `"body`": `"This is a test comment within powershell`"
`n }"

$response = Invoke-RestMethod '{$jiraticketid}/comment' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

This keeps giving me a (400) bad request error message, do I need to pass the parameter as a header?

Thanks in advance Andy.

2 answers

1 accepted

2 votes
Answer accepted


Are you sure your body is json object? 


If I were you I will use the next module to reduce the expected bugs

JiraPS working a treat, thanks for this :)

Like Gonchik Tsymzhitov likes this
0 votes

Some quick troubleshooting could be to just start with

  1. doing a print of the ticketid to see what you are storing.
  2. outputting the url you are building to make sure the concatenation is working cause that doesn't look good to me. I would suggest building the url parameter first as a variable and then inserting it in to the call. Also the { } shouldn't be needed imho

$url = "' + $jiraticketid + '/comment"

$response = Invoke-RestMethod $url -Method 'POST' -Headers $headers -Body $body

Now using the project that @Gonchik Tsymzhitov  mentions could be good alternative but since it's a basic call this could be a quick win :)

Thanks for your time Dirk, still couldn't get this working using your example. I've installed Jira PS and it's working like a dream!

Like Gonchik Tsymzhitov likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

Security Advisory for Jira Service Management

On October 20, 2021, Atlassian published a security advisory for Jira Service Management. The full advisory is available at this link.  We've seen a number of questions already asking for...

113 views 0 1
Read article

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