How to properly add/remove flag (Flagged field) to/from an issue using rest api?

I’m trying to add and remove flag from an issue using the api. Beside the fact, that Flagged field need to be added to proper screen, I’m strugling how to do it properly.

First thing is to get the Flagged field id/key. How to get it?
For now I use the rest/api/2/field end point to get all fields and I search for an item where
untranslatedName == “Flagged”
From that field I take the key and for now, it was always customfield_10021. Even for several clientIds.

Now how to set it?
From the step above I also know that the Flagged field is an array of options. (I was rather assuming it’s something like a boolean.)
Where to check what options can be set there?
Getting issue field details it turned out that the option set has id 10019.
Again, in all cases I’ve checked it was 10019.

So finally I came with a code to add a flag to an issues that looks like this:

url: “/rest/api/2/issue/47”, type:“PUT”,
data: JSON.stringify({update:{customfield_10021:[{set:[{id:“10019”}]}]}})
success: ()=>{},
error: ()=>{}

To remove a flag, just the data is modified to:

data: JSON.stringify({update:{customfield_10021:[{set:[ ]}]}})

That works. At least “on my computer”.

Is the Flagged field id always customfield_10021?
Is the Flagged option id to set it always 10019? If not, where to find the proper one?
Any documentation I did not notice about it?

Is the Flagged field id always customfield_10021 ?

No, it’s not :sob:.
I’ve just hit an instance, where following info was gathered:

Flagged field id:  {
   id: 'customfield_10300',
   key: 'customfield_10300',
   name: 'Flagged',
   untranslatedName: 'Flagged',
   custom: true,
   orderable: true,
   navigable: true,
   searchable: true,
   clauseNames: [ 'cf[10300]', 'Flagged', 'Flagged[Checkboxes]' ],
   schema: {
     type: 'array',
     items: 'option',
     custom: 'com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes',
     customId: 10300

So now the question about Flagged option id to set the Flagged field becomes much more important for us.

Maybe someone from Atlassian can show how to set Flagged field properly usin API?

Google ‘jira rest api issue flagged’ to see where the answer to setting the Flagged field has already been provided in Stack Overflow and in the Atlassian forum.

The information is also at the bottom of the Flag an issue documentation page.

Thanks for the hint. Somehow I didn’t thought to check stack overflow :man_facepalming:

Anyway, now I’ve read quite a lot of them and I’ve only seen answers which state, that the Flagged field is a checkbox type field and it’s enough to set it to Impediment.
Similarly on the Atlassian page that you provided link for, it’s stated, that the Flagged field is custom checkbox.
This seems not to be true anymore, as in all cases I’ve seen the Flagged field is of multicheckboxes type. Even check the field JSON I provided above. There is stated:

     { custom: 'com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes' }

Also in the original question I’ve described how I add/remove flag. It works and is different then the ones described on stack overflow answers.

I’ll try setting the field to “Impediment”, true or other arbitrary just to check it.

Still would be good to get a clear answer to “how to set Flagged field properly using API?” question.

I just tested against a live Jira Cloud instance, and the Flagged field came back as a single checkbox, not a multi checkbox, so I don’t where you are getting your source of information of it being a multi checkbox.

I then tried changing an Issue’s Flagged field’s value to ‘Impediment’, exactly as described in the Stack Overflow and Atlassian Community articles, by submitting a request to the Edit issue endpoint.

PUT https://{{Instance}}/rest/api/3/issue/{{issueKey}}

    "fields": {
        "customfield_10021":[ {"value": "Impediment" }]

… and it worked perfectly, and that issue was then flagged:

Everything seems to be working perfectly for me, exactly as per the documentation, so I don’t think I can help you much further.

Good luck.

All what I wrote above is done on a live cloud instance. The whole Flagged field info provided by me, comes from user instance.

The difference between what I was doing and what you did is that you used fields and I used update. So it turns out that in my case both:



  {  "customfield_10021":[ {"value": "Impediment" }]  }

do add flag to an issue.
Why the difference - I don’t know :frowning:
But looks like your way is easier and more reliable as it doesn’t require id of value to set, so I’ll use it.
Thank you @sunnyape .

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.