5

I would like to be able to add a flag to an issue via the Jira API. I was unable to find any documentation regarding this issue. Does anyone know how this works?

3
  • When you say "add a flag", what is it you are trying to do. Normally you would add a custom field to the issues through the UI then you can set the custom field using the API. Mar 29, 2016 at 7:16
  • By 'flag' do you mean label?
    – kdopen
    Mar 30, 2016 at 14:30
  • Flagging an issue is a jira implemented construct. confluence.atlassian.com/agile/jira-agile-user-s-guide/… I would just really like to be able to do this via the api. Mar 30, 2016 at 20:57

5 Answers 5

6

I've figured out how to do this, I'm not sure on the version of the API. I made a POST request to:

yourdomain /rest/greenhopper/1.0/xboard/issue/flag/flag.json

And in the body (replace JIRA-ISSUE with your issue key):

{"issueKeys":["JIRA-ISSUE"],"flag":true}

I hope this helps.

3

Here is the best answer I found. https://answers.atlassian.com/questions/38062844/answers/38062897

There is a field called Flagged. It is a checkbox type field. There is a single value by default, Impediment. The field is checked for null status. If the field is null, the issue is not flagged. If the field is not null, the issue is flagged.

You would use the REST API for this. Examples are here –

https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue.

You'll either need to know the field ID (customfield_10000) or you need to to script the discovery of the field by searching the metadata – https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-discovering-meta-data-for-creating-issues.

An example of setting a custom field while creating the issue over API –

curl -D- -u fred:fred -X POST --data {"fields":{"project":{"key":  "TEST"}, "summary": "Always do right. This will gratify some people and  astonish the REST.", "description": "Creating an issue while setting custom  field values", "issuetype":{"name": "Bug"}, "customfield_10000": [{"value":  "Impediment"}]}} -H "Content-Type: application/json"    http://localhost:8090/rest/api/2/issue/
non-minified data  Expand source
{
"fields": {
   "project":
   { 
      "key": "TEST"
   },
   "summary": "Always do right. This will gratify some people and astonish the REST.",
   "description": "Creating an issue while setting custom field values",
   "issuetype": {
      "name": "Bug"
   },       
   "customfield_10000": [ {"value": "Impediment" }]       
  }
}
1
  • 1
    But depend update is motive error Field 'customfield_10000' cannot be set. It is not on the appropriate screen, or unknown... not 100%
    – KingRider
    Sep 5, 2016 at 15:06
0

As mentioned here, "Flagged" is a checkbox custom field that accepts a single value "Impediment".

You should be able to set it using the JIRA REST API just like any other custom field. Maybe the examples here will help.

You can also set custom field values using the JIRA Java API.

1
  • 1
    Wild guesses are not helpful. As stated above, when you try to do this you end up with a vague and unhelpful "cannot be set" error. This may work like any other custom field -- maybe -- but the formatting is uncertain.
    – billmill
    Jan 27, 2022 at 6:12
0

I'm struggling with this right now. It seems that the Flagged field is not a checkbox type field anymore, but multicheckbox. So the data format I need to send to Jira Cloud API to set the flag in my case look like this:

{update:
  {customfield_10021:
    [{set:
      [{id:“10019”}]
    }]
  }
}

To remove the flag the data I sent to Jira look like this:

{update:
  {customfield_10021:
    [{set:
      []
    }]
  }
}

In the above customfield_10021 is Flagged field's key and 10019 is id that sets the flag. Both of them you need to figure out for your Jira Cloud instance for example by aquiring issue with set Flagged field and checking how it is set.

Just to make it clear, to add/remove a flag I use edit issue end point described here. Also, to be able to add/remove flag the Flagged field has to be on the edit screen of the issue type that you want to modify and your user needs to have proper priviliges.

0

I spent like 3 hours trying to figure it out and it always gave back "Field 'customfield_10021' cannot be set. It is not on the appropriate screen, or unknown.". To fix it, simply click on Settings Icon -> Issues -> Custom Fields. Search for "Flagged" click on "Screens", Add or remove associated screens" and just add it to all screens. Then it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.