@@ -748,17 +748,33 @@ def create_custom_field(
748
748
) -> T_resp_json :
749
749
"""
750
750
Creates a custom field with the given name and type
751
- :param name: str - name of the custom field
752
- :param type: str, like 'com.atlassian.jira.plugin.system.customfieldtypes:textfield'
753
- :param search_key: str, like above
754
- :param description: str
751
+ This method is primarily for Jira Server/Data Center. For Jira Cloud, the
752
+ `searcher_key` is not applicable.
753
+ :param name: str - The name of the custom field (e.g., "My Custom Field"). Cannot be empty.
754
+ :param type: str, The type of the custom field, which defines its behavior.
755
+ Example: 'com.atlassian.jira.plugin.system.customfieldtypes:textfield'
756
+ :param search_key: str, (For Jira Server/DC) The searcher key to make the field searchable.
757
+ Example: 'com.atlassian.jira.plugin.system.customfieldtypes:textsearcher'
758
+ :param description: str, An optional description for the custom field.
759
+ :return: A dictionary representing the created custom field, or None if the
760
+ API returns no content. Raises HTTPError for API-level errors.
761
+ API References:
762
+ - Jira Server: https://docs.atlassian.com/software/jira/docs/api/REST/9.17.0/#api/2/field-createCustomField
763
+ - Jira Cloud: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-fields/#api-rest-api-2-field-post
755
764
"""
756
765
url = self .resource_url ("field" )
757
- data = {"name" : name , "type" : type }
758
- if search_key :
759
- data ["search_key" ] = search_key
766
+ data = {"name" : name .strip (), "type" : type .strip ()}
767
+ if not data ["name" ]:
768
+ raise ValueError ("The 'name' for the custom field cannot be empty." )
769
+ if not data ["type" ]:
770
+ raise ValueError ("The 'type' for the custom field cannot be empty." )
771
+ # Add optional fields if they are provided
760
772
if description :
761
- data ["description" ] = description
773
+ data ["description" ] = description .strip ()
774
+ # The API expects 'searcherKey' (camelCase)
775
+ if search_key :
776
+ data ["searcherKey" ] = search_key .strip ()
777
+
762
778
return self .post (url , data = data )
763
779
764
780
def get_custom_field_option_context (self , field_id : T_id , context_id : T_id ) -> T_resp_json :
0 commit comments