Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira REST api, update a custom field options specific to a project

BIjo Punnoose
September 7, 2020

I am using REST api to update a custom field (customfield_10706) list (to add more options in the dropdown). I am using, /rest/api/3/customField/10706/option body is,

{
  "options": [
    {
      "value": "Added via API121212"
    }
  ]
}

This works correctly and adds value. But I am not sure which project it is adding to, as there are several projects in Jira and the custom field is the same in all projects. Is there an option to add ProjectKey or ProjectId somewhere for it to add in the specific project? I would ideally like this added to project with key POC2

Does this have to do anything with the basic auth user?

1 answer

0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2020

Hello @BIjo Punnoose

Thank you for reaching out.

Can you please confirm if the mentioned custom field is related to a Classic or a Next-gen project?

If you are referring to Classic projects, the same options are displayed to all projects on your site as it is the exact same field shared between all the projects. In other words, the option added to the custom field through REST API will be displayed in ALL the projects of your site.

If you want to set different custom field options for each Classic project you have, you must create a different custom field for each project and configure their contexts to be applicable only to the related project in order to avoid the confusion of having multiple custom fields with the same name and in the same project.

Now, if you are using Next-gen projects, each project has its own custom fields, so you might have several fields with the same name but different IDs. In that case, you must set the custom field ID for that specific Next-gen project in the REST API, so the options added will be reflected only in the custom field of that specific project.

Let us know if you have any questions.

BIjo Punnoose
September 9, 2020

Hi Petter,

I thought you already had details of my project as there was an option to choose which project I am etc when submitting the question. Anyways,

I am using cloud Jira and not classic. when using the REST API endpoint as below,

https://janushenderson.atlassian.net/rest/api/3/customField/<customfield>/option

and the POST body as 

{
  "options": [
    {
      "value": "Added via API121212"
    }
  ]
}

The custom field is getting updated with the entry. Now the issue,

"The custom field is getting updated with the entry BUT not to the project I want but to a default project set by admin when creating the custom field".

This custom field id the same across the different projects. As I understand we need to set a context on the custom field so as to mention as to which project do I need to associate it to. Now my straight forward question,

How do I set this via the rest API. Is there something in the json body that I need to set? An example is let us say, we have a project with key key1 and id as id1. How do I update the customfield cf1 with a context set to key1/id1 so as to it reflects in that project?

BIjo Punnoose
September 9, 2020

Can you reply with an example json body on how to set context, so as to not waste more time please? Thanks.

Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 9, 2020

Hello @BIjo Punnoose

Thank you for the details.

I believe you might have misunderstood some of the points I brought up. Sorry if I was not clear about them and please allow me to clarify it so we can confirm we are on the same page here. 

You mentioned that:

I am using cloud Jira and not classic.

I knew you were using Jira Cloud application when I added my first answer as your question is tagged as Jira Cloud, however, my question was intended to know if you are using a Classic or Next-gen project. Explaining better, Jira Cloud has two project templates (Classic and Next-gen) and they behave differently when running REST API and editing fields:

Learn the differences between classic and next-gen projects 

About this sentence:

As I understand we need to set a context on the custom field so as to mention as to which project do I need to associate it to.

Contexts do not work to hide custom field options from a project. Instead, it only restricts the whole custom field from projects. With this information in mind, I believe this is not the problem because you mentioned that the field is displayed in the project, it just doesn't get updated with the REST API.

About this sentence:

"The custom field is getting updated with the entry BUT not to the project I want but to a default project set by admin when creating the custom field".

As explained before, custom fields from Classic projects are shared between Classic projects, while each Next-gen project has its own set of custom fields (Not sharable with any other next-gen or classic projects). In other words, the field you edited is definitely not the same that is added to the project where it is not updating. They might have the same name, but definitely they have different IDs.

That being said, the behavior above can only happen in the following scenarios:

  1. You have multiple fields with the same name in a Classic project. This can cause the changes added through REST API to don't reflect in the project you want since it might be using a different field.
  2. The field you are editing (customfield_10706) is related to a Next-gen project. If that's the case, the changes applied will only reflect in the project related to that custom field.
    P.S: Since you mentioned that this field ID is also added to other projects, this option is not likely to be the root cause.
  3. The field you are editing (customfield_10706) is related to a Classic project, however, the project where it does not get updated is a Next-gen Project.

To properly identify which of the scenarios you are facing, please take a look in the documentation above to identify if the project where the field does not get updated is a Next-gen and also run a REST API in one of the issues of the project, confirming what is the custom field ID related to it:

GET /rest/api/3/issue/{issueIdOrKey}

Let us know if this information helps.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events