"OAuth 2.0 is not enabled" when trying to update custom field value using field key

I am trying update forge custom field value using “/rest/api/2/app/field/${cf_key}/value” endpoint in forge app.

Update works fine if i use id such as “customfield_12345” but i am getting this error if i use custom field key as {app-id-uuid}{environment}{extension-key} .

INFO    13:48:46.071  24f906c6aa376ddf  Unexpected async task payload: 
 {"errorMessages":["**OAuth 2.0 is not enabled for this method.**"]}
ERROR   13:48:46.084  24f906c6aa376ddf  Unexpected async task payload
Error: Unexpected async task payload
    at waitUntilComplete (webpack:///src/index.jsx:73)
    at viewIssueEvent (webpack:///src/index.jsx:42)

My index file is

import { storage } from '@forge/api';

const logRow = function(time_p, issueKey_p, accountId_p) {
    const time = time_p;
    const issueKey = issueKey_p;
    const accountId = accountId_p;
    return { time, issueKey, accountId };
};
const cf_key = "ari:cloud:ecosystem::app/a9dfba4b-20d0-41c2-9237-2823ec6aeabb__development__issue-whosee"; // DOES NOT WORK
const cf_id = "customfield_10175"; // WORKS

const cf_value = 14;

export async function viewIssueEvent(event, context) {

/* 	console.log("ISSUE KEY = "+event.issue.key);
	console.log("ISSUE ID  = "+event.issue.id);
	console.log("USER  ID  = "+event.atlassianId); */
	
	//const { activityItem: { object: { localResourceId: issueId } } } = event;
	const issueId  = event.issue.id;

    console.log(`Running for issue ${issueId}`);

    const respnse=await requestJira("PUT", `/rest/api/2/app/field/${cf_id}/value`, { //cf_key does not work
        "updates": [
          {
            "issueIds": [
                issueId
            ],
            "value": cf_value
          }
        ]
      });

    await waitUntilComplete(respnse);

    console.log(`Response: ${respnse.status} ${respnse.statusText}`);    

/* 	console.log(`Updated the attachment count of issue ${issueId} `);
	
	const currentTime = new Date().valueOf() ;
	const key = event.issue.key + "_" + currentTime;
	storage.set(key, logRow(currentTime, event.issue.key, event.atlassianId));

	await storage.get(key).then((row) => console.log(JSON.stringify(row))); */
}

async function requestJira(method, url, body, responseTransformer = async r => await r.json()) {
    console.log(`REQUEST: ${method} ${url}`);
    const response = await api.asUser().requestJira(url, {
        method: method,
        body: JSON.stringify(body)
    });
    return responseTransformer(response);
}

async function waitUntilComplete(asyncTask) {
    if (asyncTask.self) {
        let currentResponse = asyncTask;
        while (!currentResponse.finished) {
            await new Promise(resolve => setTimeout(resolve, 100)); // wait 100ms before asking for the next status update
            currentResponse = await requestJira('GET', currentResponse.self, null);
        }
        console.log(`Task "${currentResponse.description}" finished with message: "${currentResponse.description}".`);
    } else {
        console.log("Unexpected async task payload: \n", JSON.stringify(asyncTask));
        throw Error("Unexpected async task payload");
    }
}

Hello, @MertTurkoglu,

It seems you are not using the correct key of your field. If you head over to the documentation you will find the following passage there:

The created field has its key set to {app-id-uuid}__{environment}__{extension-key} , where:

  • {app-id-uuid} is the tail part of your app ID defined in the manifest (for example: ari:cloud:ecosystem::app/{app-id-uuid} ).
  • {environment} is the environment in which the app is installed.
  • {extension_key} is the key of the custom field extension defined in the manifest.

In other words, your key is a9dfba4b-20d0-41c2-9237-2823ec6aeabb__DEVELOPMENT__issue-whosee (notice the uppercase environment name). To double check if it’s correct, use the Get fields REST API – it will return all fields on an instance along with their keys.

I can see now how it might be a failure of this documentation to provide an example in addition to this dry specification. I think it would make things that much clearer.

Hope this helps, let me know if you have any more questions.

2 Likes