Need help working with issues? In Jira Software, issues help you manage code, estimate workload, and keep track of your team. On this page, you'll find a quick overview of everything that you can do with an issue.
This resource represents Jira issues. Use it to:
create or edit issues, individually or in bulk.
retrieve metadata about the options for creating or editing issues.
delete an issue.
assign a user to an issue.
get issue changelogs.
send notifications about an issue.
get details of the transitions available for an issue.
transition an issue.
Custom Fields
In the Jira REST API, custom fields are uniquely identified by the field ID, as the display names are not unique within a Jira instance. For example, you could have two fields named "Escalation date", one with an ID of "12221" and one with an ID of "12222". A custom field is actually referenced by customfield\_ + the field ID, rather than just the field ID.
Note: For example, the "Story points" custom field with ID = "10000" is referenced as customfield_10000 for REST calls. You can get this reference identifier by requesting the create metadata for the issue type.
We support the following custom field types.
Group(s) Picker
User(s) Picker
URL's
Text
Number
Date
DateTime
Select
MultiSelect
RadioButton
CheckBox
Cascading Multiselect
The examples below show how to set the values for different types of custom fields in the input data.
Edits an issue. The edits to the issue's fields are defined using update and fields. There're two ways to edit an issue on Jira, implicit and explicit.
Simple update (implicit set via "fields")
The simple way to update an issue is to do a GET, update the values inside "fields", and then PUT back.
If you PUT back exactly what you GOT, then you are also sending "names", "self", "key", etc. These are ignored.
You do not need to send all the fields inside "fields". You can just send the fields you want to update. Absent fields are left unchanged. For example, to update the summary:
var payload =jira.IssueScheme{ Fields: &jira.IssueFieldsScheme{ Summary: "New summary test test", }, }
Some fields cannot be updated this way (for example, comments). Instead you must use explicit-verb updates (see below). You can tell if a field cannot be implicitly set by the fact it doesn't have a SET verb.
If you do send along such un-SET-able fields in this manner, they are ignored. This means that you can PUT what you GET, but not all of the document is taken into consideration.
Operation (verb) based update (explicit verb via "update")
Each field supports a set of operations (verbs) for mutating the field. You can retrieve the editable fields and the operations they support using the "editmeta" resource.
The editmeta endpoint is not mapped, yet refer to this ticket
The basic operations are defined below (but custom fields can define their own).
The general shape of an update is field, array of verb-value pairs, for example:
//Issue Update Operationsvar operations =&jira.UpdateOperations{}err = operations.AddArrayOperation("custom_field_id", map[string]string{"value": "verb","value": "verb","value": "verb","value": "verb",})if err !=nil { log.Fatal(err)}// If the need to add multi-array customfields, you can the following method:// In this particular example, we're going to the manipulate the fixVersions field.err = operations.AddMultiRawOperation("fixVersions", []map[string]interface{}{ {"remove": map[string]interface{}{"name": "Version 00", }, }, {"remove": map[string]interface{}{"name": "Version 101", }, }, {"add": map[string]interface{}{"name": "Version 301", }, },})
SET: Sets the value of the field. The incoming value must be the same shape as the value of the field from a GET. For example, a string for "summary", and array of strings for "labels".
ADD: Adds an element to a field that is an array. The incoming value must be the same shape as the items of the array in a GET. For example, to add a label:
REMOVE: Removes an element from a field that is an array. The incoming value must be the same shape as the items of the array in a GET (although you can remove parts of the object that are not needed to uniquely identify the object).
EDIT: Edits an element in a field that is an array. The element is indexed/identified by the value itself (usually by id/name/key).
Assigns an issue to a user. Use this operation when the calling user does not have the Edit Issues permission but has the Assign issue permission for the project that the issue is in.
Creates an email notification for an issue and adds it to the mail queue.
packagemainimport ("context""github.com/ctreminiom/go-atlassian/jira/v2""github.com/ctreminiom/go-atlassian/pkg/infra/models""log""os")funcmain() {var ( host = os.Getenv("HOST") mail = os.Getenv("MAIL") token = os.Getenv("TOKEN") ) atlassian, err := v2.New(nil, host)if err !=nil {return } atlassian.Auth.SetBasicAuth(mail, token)var userRecipients []*models.IssueNotifyUserScheme userRecipients = append(userRecipients, &models.IssueNotifyUserScheme{AccountID: "87dde939-73be-465f-83c5-2217fb9dd9de"})
userRecipients = append(userRecipients, &models.IssueNotifyUserScheme{AccountID: "8abc0d5f-5eb9-48af-bd8d-b83451828a40"})
var groupsRecipients []*models.IssueNotifyGroupScheme groupsRecipients =append(groupsRecipients, &models.IssueNotifyGroupScheme{Name: "jira-users"}) groupsRecipients =append(groupsRecipients, &models.IssueNotifyGroupScheme{Name: "scrum-masters"}) opts :=&models.IssueNotifyOptionsScheme{// The HTML body of the email notification for the issue. HTMLBody: "The <strong>latest</strong> test results for this ticket are now available.",// The subject of the email notification for the issue.// If this is not specified, then the subject is set to the issue key and summary. Subject: "SUBJECT EMAIL EXAMPLE",// The plain text body of the email notification for the issue.// TextBody: "lorem",// The recipients of the email notification for the issue. To: &models.IssueNotifyToScheme{ Reporter: true, Assignee: true, Watchers: true, Voters: true, Users: userRecipients, Groups: groupsRecipients, },// Restricts the notifications to users with the specified permissions. Restrict: nil, } response, err := atlassian.Issue.Notify(context.Background(), "KP-2", opts)if err !=nil { log.Fatal(err) } log.Println("HTTP Endpoint Used", response.Endpoint)}
Get transitions
GET /rest/api/{2-3}/issue/{issueIdOrKey}/transitions
Returns either all transitions or a transition that can be performed by the user on an issue, based on the issue's status.
POST /rest/api/{2-3}/issue/{issueIdOrKey}/transitions
Performs an issue transition.
Performs an issue transition and, if a transition screen is associated, updates the relevant fields from that screen.
To update fields on the transition screen, include the desired field values in the fields or update parameters within the request body. You can retrieve details about these fields by using the Get transitions endpoint with the transitions.fields expand option.