Hi All,
I'm currently working on a PowerShell function which would create Jira issues via REST API. Once the issue is created, the ideal would be to move the item to an active sprint.
During testing, I tried to make the move based on the official Atlassian documentation https://developer.atlassian.com/cloud/jira/software/rest/api-group-sprint/#api-rest-agile-1-0-sprint-sprintid-issue-post
When I try to run invoke-restmethod, I do not get any error message instead PowerShell returns a PS custom object with all the issues which are in the given sprint but the actual move of the issue to this sprint does not happen.
Any help on this matter would be appreciated.
The Json variable looks like this:
$Json = @"
{
"issues":
[
"issueID"
]
}
"@
hello @Alexandra
You can set the sprint value during the creation. The only trick here that you should not use the field name "Sprint", you have to get the "Sprint" field ID in JIRA. This link will help you for this point.
Below is a Sample Powershell code for creating and JIRA Issue within a specific sprint. In my case my JIRA Sprint field ID was 10020 and active sprint ID was 1 (highlighted in bold).
Powershell Code
# Use your user name (email address) and the password is the API Key
$cred = Get-Credential
$ParamsCreate = @{
Uri = "https://egyptcommunity-dev.atlassian.net/rest/api/2/issue"
Authentication = "Basic"
ContentType = "application/json"
Credential = $cred
}
#Json Data for JIRA Ticket details
$Data = '{
"fields": {
"project": {
"key": "CMP1"
},
"summary": "Sprint issue test",
"description": "REST APIs are great.",
"issuetype": {
"name": "Story"
},
"customfield_10020": 1
}
}'
# Create the JIRA Ticket within my active sprint
Invoke-RestMethod @ParamsCreate -Method Post -Body $Data
Code Results
JIRA Check
Cheers,
Karim
Many thanks for your quick help!
I tried to follow this guide earlier that you recommended but the problem is that in our Jira version there is no Custom fields under Fields, the Administration field looks different, maybe this is another version.
I was able to get the sprint id of a specific sprint but what I'd like to achieve is that the script will always move the issue to the current active sprint. Do you have any other suggestions how the custom field id can be obtained?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexandra
You may try the below steps (tested on Cloud Version)
Cheers,
Karim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Trudy,
Thank you.
For the sprint move I use the following:
$jiraresturl= "http://jira9.domain.com/rest/agile/1.0/sprint/{sprintID}/issue
$Json = @"
{
"issues":
[
"issueID"
]
}
"@
Invoke-restmethod -Method Post -uri $jiraresturl -Websession $jirasession -Body $Json -ContentType "application/json" -ErrorAction Stop
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.