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

Jira API - Passing powershell parameter

Andy McKee February 14, 2021

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{
`n `"body`": `"This is a test comment within powershell`"
`n }"

$response = Invoke-RestMethod 'https://EXAMPLE.atlassian.net/rest/api/2/issue/{$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
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2021

Hi! 

Are you sure your body is json object? 

 

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

https://github.com/AtlassianPS/JiraPS

Andy McKee February 16, 2021

JiraPS working a treat, thanks for this :)

Like Gonchik Tsymzhitov likes this
0 votes
Dirk Ronsmans
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 15, 2021

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 = "https://EXAMPLE.atlassian.net/rest/api/issue/' + $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 :)

Andy McKee February 16, 2021

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
TAGS
AUG Leaders

Atlassian Community Events