Edit forge app created custom field from rest api

I seem to be having some trouble updating a custom field value. I created this custom field with the forge app. And I’m now updating it from a separate program. currently my code is setup as follows.

var myHeaders = new Headers();
    myHeaders.append(
      "Authorization",
      "Basic" +
        Buffer.from(
          `${configObject.Username}:${configObject.ApiKey}`,
          "utf-8"
        ).toString("base64")
    );
    myHeaders.append("Accept", "application/json");
    myHeaders.append("Content-Type", "application/json");

    let bodyData = `{
        "update":{
            "customfield_15422":{
                "set": {
                  "Cases":[
                      {
                          "label": 123456,
                          "value": 123456
                      }
                  ]
              }
            }
        }
    }`;

    var requestOptions = {
      method: "PUT",
      headers: myHeaders,
      redirect: "follow",
      body: bodyData,
    };

    fetch(`${configObject.RootUrl}/rest/api/3/issue/JSTB-31`, requestOptions)
      .then((response) => {
        if (response.ok) {
          response.text();
        }
        throw new Error(response.status + " " + response.statusText);
      })
      .then((result) => console.log(result))
      .catch((error) => console.log("error", error));

Is it not possible to edit forge app created custom fields via a rest api call from something other the the app that created the field? I have seen a lot of different information around the docs pages. Any help would be appreciated.

Hi @barron_brock
When a custom field is created via a forge app, its locked for editing on the UI and via Rest API. It’s managed by the app.
Alternatively if the app creates a custom field type, admins can create custom fields and manage them via native UI or Rest API.

Thank you.

Hi! thank you for your quick response! Is it possible to update the value of said custom field? Say the field’s value is equal to 2, and I want it to equal 3. Is this also not possible via rest api?

So not editing the field in anyway, just it’s value?

1 Like

So I cannot edit the custom field via the api. Thanks @ImranParvez for the clarification. If anyone stumbling across this wants to simply edit the value of said field, here is some code that does so

function updateJiraTickets(ticketsToUpdate, configObject) {
  ticketsToUpdate.forEach((ticket) => {
    var myHeaders = new Headers();
    myHeaders.append(
      "Authorization",
      "Basic " +
        Buffer.from(`${configObject.Username}:${configObject.ApiKey}`).toString(
          "base64"
        )
    );
    myHeaders.append("Accept", "application/json");
    myHeaders.append("Content-Type", "application/json");

    //this is following the schema of my custom field
    let bodyPayload = `
          {
            "fields":{
              "${configObject.customFieldId}": {
                "Cases":[
                  {
                    "label":"${ticket.ticketValue}",
                    "value":"${ticket.ticketValue}"
                  }
                ]
              }
            }
          }
    `;

    var requestOptions = {
      method: "PUT",
      headers: myHeaders,
      redirect: "follow",
      body: bodyPayload,
    };

    fetch(
      `${configObject.RootUrl}/rest/api/3/issue/${ticket.ticketName}`,
      requestOptions
    )
      .then((response) => {
        console.log(`Response ${response.status} ${response.text}`);
        if (response.status == 204) console.log("update successful!");
        return response.text();
      })
      .then((result) => console.log(result))
      .catch((error) => console.log("error", error));
  });
}
1 Like