Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to move Jira issues to a specific sprint via REST API?

Alexandra November 18, 2022

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"

    ]

}

"@

2 answers

0 votes
Karim ABO HASHISH
Community Champion
November 18, 2022

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


Create-issue-in-sprint-restapi-powershell.png

JIRA Check

Sprint-Board-Createissue-restapi.png

Cheers,

Karim

Alexandra November 21, 2022

Hi @Karim ABO HASHISH,

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.

Karim ABO HASHISH
Community Champion
November 21, 2022

Hi @Alexandra

You may try the below steps (tested on Cloud Version)

  1. While you are logged in, type gg or --> it will pop the special admin menu, then type custom field.

    special-admin-menu-custom-fields.png

  2. Search for the field sprint, and from the 3 dot icon on the right, select view information

    Get-Sprint-Field-info.png

  3. You can find your sprint field ID in the URL

    sprint-custom-field-id.png

 

Cheers,

Karim

0 votes
Trudy Claspill
Community Champion
November 18, 2022

Hello @Alexandra 

Welcome to the community.

Can you show us the actual code you are using?

Alexandra November 21, 2022

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

Suggest an answer

Log in or Sign up to answer