Is it possible to supress notifications when Forge App makes changes

Is it possible for the forge app to not send notifications when editing an issue?

I know the REST API call has the notifyUsers parameter. I have tried to used this but when making the request asApp() I get a 403 error. This means my add on is does not have enough privileges. How can I elevate its privileges to be able to not send notifications?

async function setIssueBackLogLabel(issueKey, toBacklog){
    /**
     * @issueKey - the Jira issueKey number for the issue.
     * @toBacklog - Bolean which spcifies to add or remove backlog label
     * @example setIssueBackLogLabel('key', true)
     */
    const val = toBacklog ? {"add": "EPICBACKLOG"} : {"remove": "EPICBACKLOG"};
    const requestUrl = route`/rest/api/3/issue/${issueKey}?notifyUsers=false`; 
    const body = {
           "update": 
               {
                "labels": [val],
               }
   };

    try{
        let response = await api.asApp().requestJira(requestUrl, {
            method: "PUT",
            headers: {
                "Content-Type": "application/json",
                'Accept': 'application/json'
            },
            body: JSON.stringify(body)
        });
        if (response.status !== 201) {
            console.log(response.status);
        }
        return response;
    }catch(err){
        console.log(err.message)
    }
}

Yes, it is possible. To use that query param, the user making the request needs appropriate permissions, as stated in the documentation:

To disable the notification, administer Jira or administer project permissions are required. If the user doesn’t have the necessary permission the request is ignored.

For the app to get those permissions, it needs to have appropriate scopes defined in the manifest. I was able to make the request with the following scopes:

permissions:
  scopes:
    - write:jira-work
    - manage:jira-project
    - manage:jira-configuration

Note that manage:jira-project should grant the project admin permission, while manage-jira-configuration grants the global admin permission. Meaning, only one of those should be necessary (you can experiment).

Now, the tricky part is that Jira permissions seem to be granted for the app only on the first installation. So if you already installed your app and added new scopes later, there is a high chance it won’t work: in this case you would need to regenerate your app’s ID with forge register and install it fresh.

By the way, I recommend checking the actual payload of the error response, not only the status code, it often contains useful information. Something like this:

        if (response.status !== 201) {
            console.log(response.status);
            console.log(await response.json()); // this should be useful
        }
2 Likes

Hi kkercz

I just tried out your suggestion and its working! I had already changed the permissions but I had not reregistered the app so I think that did the trick. Thanks for logging tip as well, should help with my debugging.

1 Like