Forge App can comment on JPD issues but not update fields

Hi All,

I have a forge app that listens for labels to get applied a JPD issue and then performs some actions. Some of the actions are to leave a comment and to update some of the issue’s fields(Label and custom field).

The app will successfully add a comment to the issue but fails to update any of the fields. When attempting to update the label I receive:

Error processing issue ST-2: Error: Remove label pb_create for ST-2 failed (400): {"errorMessages":[],"errors":{"labels":"Field 'labels' cannot be set. It is not on the appropriate screen, or unknown."}}

Using postman, I am able to successfully update the label and customfield with the same api key.

My manifest:

permissions:
  scopes:
    - read:jira-work
    - write:jira-work
    - read:issue-details:jira
    - read:issue-meta:jira
    - read:confluence-content.all
    - write:confluence-content
    - write:page:confluence
    - write:label:confluence
    - read:content-details:confluence
    - manage:jira-configuration
    - storage:app
    - read:page:confluence
    - write:confluence-file

Code to update custom field:

export async function updateIssueField(issueKey, fieldIdOrName, value) {
    console.log(`API - updating Jira issue field ${fieldIdOrName}`)
    const body = {
        fields: {
            [fieldIdOrName]: value,
        },
    }
    const response = await api.asApp().requestJira(route`/rest/api/3/issue/${issueKey}`, {
        method: 'PUT',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(body),
    })
    await handleResponse(response, `Update issue ${issueKey}`)
}

What am I missing from my forge app that is preventing me from successfully updating a jira issue?

Hello @MichaelFlores

Can you please provide the actual JS code from your Forge app that shows the actual values for all the variables and constants, not just some sample JS.

Also, if the request works in Postman, please provide the full request you made, including the entire path, the entire request body etc etc.

Hi @sunnyape ,

Provided is the actual implementation, but below are the values

issueKey = ‘ST-2’

fieldIdOrName = ‘customfield_10150’

value = ‘htps://www.google.com‘

body: = {
“fields”: {
“customfield_10150”: “htps://www.google.com“
}
}

Running it results in the below error.

Error processing issue ST-2: Error: Update issue ST-2 failed (400): {“errorMessages”:,“errors”:{“customfield_10150”:“Field ‘customfield_10150’ cannot be set. It is not on the appropriate screen, or unknown.”}}

Using postman

PUT: htps://mydomain.net/rest/api/3/issue/ST-2

{
  "fields": {
"customfield_10150": "https://www.google.com"
  }
}

Results in a 204 and the field is being updated.

I was hoping you’d provide the actual JS that showed exactly how the declarations of the variables and constants had been made, not just describe their values… but anyhow.

When you put all the values into your JS directly, not via variables / constants, does it work? IE, just put the actual Body text directly into the requestJira method itself.

It SOUNDS like you’ve done it correctly in JS, so that leaves the other possibilities such as not having updated and re-published the app so that the scopes declared in the manifest have been properly applied.

I’ve redeployed the app. Added manage:jira-project at the suggestion of a bot. Reinstalled at the behest some forge message. But am still getting the error message. I’ve added Labels to all my screens via Jira Settings > Work Items > Screens.

I created a Software Space (as opposed to the Discovery Space), tested, and everything worked.

This would appear to be something unique to Discovery Spaces vs at least Software Spaces.

Oh, I see. I missed that part of the question where you said it was about JPD and just assumed you were talking about a ‘normal’ Jira space.

If the request to the same API endpoint works in Postman for that field in that space using an OAuth token with the same scopes as your app’s manifest, it should work using requestJira(), but that’s not always guaranteed. I’ll have to leave your question to someone who knows if that method has any known problems with Product Discovery spaces.

Maybe also search through JAC and see if it’s already been logged as a bug?

All good. Thanks I’ll search through the JAC in the meantime

1 Like

Behold, https://jira.atlassian.com/browse/ECO-847. asUser didn’t work for me, I ended up needing to add the authorization header to make updates to JPD issues.

const response = await api.asApp().requestJira(route`/rest/api/3/issue/${issueKey}`, {
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...authorizationHeader() },
        body: JSON.stringify({ update: { labels: [{ set: updatedLabels }] } }),
    })