Editing Jira fields via API

api.png

If you're working with Jira REST API on a daily basis then this article is for you. As you may have realised that you can do a lot with it with scripting certain functions. Also taking that extra step to automate those certain features can be challenging at times but fulfilling that aim makes it worthwhile. There are many programming languages that can be used to implement a solution but choosing the right one that has lots of support would help you attain the answers you seek.

I'm here to share with you about how I can update certain Jira fields using python with a package I wrote called jiraone

The package provides a Field class which has the ability to update Jira's custom or system fields on an issue or issues simply by specifying the field name alone. In the event the field cannot be found, it returns an error that the field value cannot be None. Example of fields type that can be queried:

  • Cascading select field
  • Multi select or multi checkboxes field
  • Components or Fix versions field 

Adding values to a multiselect field

from jiraone import field, echo, LOGIN

user = "email"
password = "token"
link = "https://yourinstance.atlassian.net"
LOGIN(user=user, password=password, url=link)

issue = "T6-75"
fields = "Multiple files" # a multiselect custom field
case_value = ["COM Row 1", "Thanos"] for value in case_value: c = field.update_field_data(data=value, find_field=fields, key_or_id=issue, options="add", show=False) echo(c) # output # < Response[204] >

With the above, you can easily add multiple values or remove multiple values from a multiselect field on an issue or on any issue.You can look into the documentation here to get more details on its usage.

Posting values to a cascading select field

from jiraone import field, echo, LOGIN

user = "email"
password = "token"
link = "https://yourinstance.atlassian.net"
LOGIN(user=user, password=password, url=link)

issue = "T6-75"
fields = "Test cascading" # a cascading select custom field
value = ["Servers", "Redhat"] # a list of First level & second level
c = field.update_field_data(data=value, find_field=fields, key_or_id=issue, show=False)
echo(c)

# output
# < Response[204] >

You can specify the first level and second level of the cascading field. Look into the documentation here for more details.

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events