Bulk edit issue not working properly

Hi there,

I’m currently exploring the Bulk Edit Issue APIs from Jira Cloud REST APIs to update issue labels. My goal is to replace a specific label with a new label, but I’ve encountered some limitations.

Using the REPLACE operation replaces all existing labels with the provided new label, which is not ideal for this use case. I’ve also tried combining REMOVE and ADD operations as a workaround, but this approach doesn’t seem to work as expected.

Here are the code snippets for reference:

Attempt 1: Using REPLACE

const bodyData = {
  sendBulkNotification: false,
  selectedIssueIdsOrKeys: issues.map(issue => issue.key),
  selectedActions: ["labels"],
  editedFieldsInput: {
    labelsFields: [
      {
        bulkEditMultiSelectFieldOption: "REPLACE",
        fieldId: "labels",
        labels: [
          {
            name: currentLabel?.name
          }
        ]
      },
    ]
  }
};

const res = await requestJira(`/rest/api/3/bulk/issues/fields/`, {
  method: "POST",
  body: JSON.stringify(bodyData),
  headers: {
    "content-Type": "application/json",
    Accept: "application/json"
  }
});
const jsonRes = await handleJiraResponse(res);
console.log("jsonRes", jsonRes);

Attempt 2: Combining REMOVE and ADD

const bodyData = {
  sendBulkNotification: false,
  selectedIssueIdsOrKeys: issues.map(issue => issue.key),
  selectedActions: ["labels"],
  editedFieldsInput: {
    labelsFields: [
      {
        bulkEditMultiSelectFieldOption: "REMOVE",
        fieldId: "labels",
        labels: [
          {
            name: currentLabel?.name
          }
        ]
      },
      {
        bulkEditMultiSelectFieldOption: "ADD",
        fieldId: "labels",
        labels: [
          {
            name: newLabel
          }
        ]
      }
    ]
  }
};

const res = await requestJira(`/rest/api/3/bulk/issues/fields/`, {
  method: "POST",
  body: JSON.stringify(bodyData),
  headers: {
    "content-Type": "application/json",
    Accept: "application/json"
  }
});
const jsonRes = await handleJiraResponse(res);
console.log("jsonRes", jsonRes);

Both attempts haven’t yielded the desired result. Is there a recommended way to replace only a specific label without affecting the others? Alternatively, is this functionality planned for future updates, or am I missing something in the API documentation?

Any insights or suggestions would be greatly appreciated!

Hi @UmeshChaudhary !
I just tried it and I was able to remove the label which you want to replace and then add a new label but I had to do it in 2 calls. First:

{
  "sendBulkNotification": false,
  "selectedIssueIdsOrKeys": ["MAT-804"],
  "selectedActions": ["labels"],
  "editedFieldsInput": {
    "labelsFields": [
      {
        "bulkEditMultiSelectFieldOption": "REMOVE",
        "fieldId": "labels",
        "labels": [
          {
            "name": "label2"
          }
        ]
      }
       
      
    ]
  }
}

and then add

{
  "sendBulkNotification": false,
  "selectedIssueIdsOrKeys": ["MAT-804"],
  "selectedActions": ["labels"],
  "editedFieldsInput": {
    "labelsFields": [
      {
        "bulkEditMultiSelectFieldOption": "ADD",
        "fieldId": "labels",
        "labels": [
          {
            "name": "label1"
          }
        ]
      }      
    ]
  }
}

It does not work in 1 call.

Hi @alex_sam ,

Thank you for prompt reply and a solution.

However, this introduces additional complexity in our workflow. Not only do we need to handle these as two separate calls, but we also have to manage long polling for the status of the tasks these API calls returns for success/errors. This adds overhead in terms of both development and performance.

It would be much more efficient and user-friendly if Atlassian could provide a more streamlined solution, allowing for label replacement in a single API call or at least addressing this limitation more directly.