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");
}
}