Add value to custom field (single/multi select) via rest API
Asked by Jochen Betz:

As Jira does not support out of the box usage of versions of a different project in the service management project I decided to create a custom field reproducing the same options (versions) as in the development project.  
Now, each time a new release is created in the development project I need to add this version manually in the service management custom field as an option.  

I'm currently using the python jira API for some interactions anyway. But I could not find a way to achieve what I described above. But neither did I find a way to invoke the low level rest API.  
What I'm able to do is to get the current possibilities of a custom field. Albeit it's already weird that one needs an issue to get to the field instead of accessing the field directly.  
And as well it's unfortunate in this case, that it's not just a simple list of values but a list containing among others a unique ID for each option; which makes it impossible to just add a value - because how should we create this ID?  

Thus: How can you add a new option to the "allowed Values" of a custom field either (best) via jira python or alternatively using the rest API direct?


Answers:
author: Lina Kuhn
body: Hi [@Jochen Betz](/t5/user/viewprofilepage/user-id/5276364) ,  

The first thing that came into my mind is to use a global automation instead. You can find a tutorial [here](https://confluence.atlassian.com/jirakb/how-to-copy-a-version-from-a-project-to-another-project-1332805812.html) that describes how to copy versions among different projects.  

If you want to solve it via REST API, I would suggest to [use v3](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-group-issue-custom-field-options). You can access customfield options of a field via its context id (without an actual issue) using <https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-get>

The same way you can post new options with <https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-post>  

The mentioned documentation contains also example snippets for python.

comments: author: Jochen Betz
body: Thank you [@Lina Kuhn](/t5/user/viewprofilepage/user-id/5462042) for your reply. I'm currently working on using the low level access with python/request/json/rest API. Albeit it would be neither if the jira python lib would support this. Thanks for pointing in the right direction.

Especially thanks for the link to how to solve it with global automation, that's definitely a good solution to go for with new created versions.


author: Jochen Betz
body: As [@Lina Kuhn](/t5/user/viewprofilepage/user-id/5462042) was suggesting, I used global automation rules. Unfortunately the Jira API is pretty inconsistent and incomplete, even after all this years. While it has a building block to react to "version creation" it does not have a block to allow "creating version" on the other side. ANd this "pattern" occurs not just in this place. Each time you have eventually to fiddle around with Web Send Requests to the REST API.  

After figuring out how to somehow use web send requests (still open question about storing the response in a variable see [HERE](https://community.atlassian.com/t5/Jira-Service-Management/Iterating-over-elements-of-quot-Send-web-request-quot/qaq-p/2676307#U2676337)) it turned out it was almost for nothing.  
All this copy (aka duplicating, which is usually a bad idea) the versions from one project to another I was NOT able to use these in the especially designed fields of type "version picker" on forms. Why? God knows, especially is it is a known [problem](https://jira.atlassian.com/browse/JSDCLOUD-86)  

So it just the creation of yet another rule, another custom field another duplication.  

Conclusions: Jira/Atlassian never fails to disappoint.


author: Jochen Betz
body: Thanks again [@Lina Kuhn](/t5/user/viewprofilepage/user-id/5462042) . The global automation for simply creating a new version in project B when one is created in project A was done rather quick and works well.

The attempt to copy all versions from project A to project B using web request and rest API was a nightmare. Eventually I managed to achieve what I wanted, but not all issues solved along the way.


Tags: cloud

jira-service-management

jira-service-management-cloud