Skip to content

Commit 8c4e39e

Browse files
committed
Add get_custom_field_options method
1 parent efcfb44 commit 8c4e39e

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

atlassian/jira.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,60 @@ def get_custom_field_option(self, option_id: T_id) -> T_resp_json:
713713
url = f"{base_url}/{option_id}"
714714
return self.get(url)
715715

716+
def get_custom_field_options(
717+
self,
718+
field_id: T_id,
719+
project_id: T_id,
720+
issue_type_id: Optional[T_id | list[T_id]] = None,
721+
query: Optional[str] = None,
722+
page: Optional[int] = None,
723+
limit: Optional[int] = None,
724+
sort: Optional[bool] = None,
725+
use_all_contexts: Optional[bool] = None,
726+
) -> T_resp_json:
727+
"""
728+
Get list of all options available for a custom field in a specified project.
729+
Numeric field ID and numeric project ID must be used.
730+
731+
This is Experimental API available to Jira data Center.
732+
At the time of testing, providing multiple project IDs results in 404 response.
733+
734+
Reference: https://developer.atlassian.com/server/jira/platform/rest/v11003/api-group-customfields/#api-api-2-customfields-customfieldid-options-get
735+
736+
:param field_id: str - The ID of the custom field.
737+
:param project_id: str - The project ID in a context.
738+
:param issue_type_id: str, Optional - A list of issue type IDs in a context.
739+
:param query: str, Optional - A string used to filter options.
740+
:param page: int, Optional - The page of options to return, starting from 1.
741+
:param limit: int, Optional - The maximum number of results to return. If empty, return all results.
742+
:param sort: bool, Optional - Flag to sort options by their names.
743+
:param use_all_contexts: bool, Optional - Flag to fetch all options regardless of context, project IDs, or issue type IDs.
744+
"""
745+
url = self.resource_url(
746+
f"customFields/{field_id}/options",
747+
api_version=2,
748+
)
749+
params: dict = {}
750+
if project_id:
751+
if isinstance(project_id, (list, tuple, set)):
752+
project_id = ",".join(project_id)
753+
params["projectIds"] = project_id
754+
if issue_type_id:
755+
if isinstance(issue_type_id, (list, tuple, set)):
756+
issue_type_id = ",".join(issue_type_id)
757+
params["issueTypeIds"] = issue_type_id
758+
if query:
759+
params["query"] = query
760+
if page is not None:
761+
params["page"] = page
762+
if limit is not None:
763+
params["maxResults"] = limit
764+
if sort is not None:
765+
params["sortByOptionName"] = sort
766+
if use_all_contexts is not None:
767+
params["useAllContexts"] = use_all_contexts
768+
return self.get(url, params=params)
769+
716770
def get_custom_fields(self, search: Optional[str] = None, start: int = 1, limit: int = 50) -> T_resp_json:
717771
"""
718772
Get custom fields. Evaluated on 7.12

docs/jira.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ Manage projects
217217
# Using " " string (space) for username gives All the active users who have browse permission for a project
218218
jira.get_users_with_browse_permission_to_a_project(username, issue_key=None, project_key=None, start=0, limit=100)
219219
220+
# Get existing custom fields or find by filter
221+
jira.get_custom_fields(search=None, start=1, limit=50):
222+
223+
# Returns a full representation of a Custom Field Option that has the given id.
224+
option_id = 10001
225+
jira.get_custom_field_option(option_id)
226+
227+
# Returns full list of Custom Field Options in a specified project.
228+
field_id = 10000
229+
project_id = 1234
230+
jira.get_custom_field_options(field_id, project_id, issue_type_id=None)
231+
220232
Manage issues
221233
-------------
222234

@@ -240,9 +252,6 @@ Manage issues
240252
value = {"name": "username"}
241253
jira.issue_field_value_append(issue_id_or_key, field, value, notify_users=True)
242254
243-
# Get existing custom fields or find by filter
244-
jira.get_custom_fields(search=None, start=1, limit=50):
245-
246255
# Check issue exists
247256
jira.issue_exists(issue_key)
248257

0 commit comments

Comments
 (0)