Problems with Put REST API

Hi, I’m, having problems with using the REST API put to update comments. I saw that the structure of a put is very similar to POST however, when I try to use PUT, It doesn’t do anything. Here’s my code below, it’s very similar to the sample one shown in https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-id-put. Since its so similar to POST, I tried changing the method to POST and the requestUrl to /rest/api/3/issue/${issueId}/comment/ and the works perfectly fine but for some reason PUT does not.

async function updateComment(issueId, commentId, bodyData) {
	console.log(`starting update`);
	const requestUrl = `/rest/api/3/issue/${issueId}/comment/${commentId}`;
	console.log(requestUrl);
	const newbody = { 
		"body": bodyData
	};
	
	const response = await api.asApp().requestJira(requestUrl, {
	  method: 'PUT',
	  headers: {
		'Accept': 'application/json',
		'Content-Type': 'application/json'
	  },
	  body: JSON.stringify(newbody)
	});
	
	console.log(`updateComment Response: ${response.status} ${response.statusText}`);
	 if (response.status !== 200) {
         console.log(response.status);
         throw `Unable to add comment to issueId ${issueId} Status: ${response.status}.`;
     }

	return(await response.json());
}
1 Like

This is a different API then the one you’re having issues with to update a comment. This one expects a POST see docs here https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-post This API is adding a comment not updating it. That’s why POST works there and not PUT.

What does the data look like that you’re passing into the function?
Is your bodyData variable coming into the function as Atlassian Documentation Format (ADF)?

{
  "body": {
    "type": "doc",
    "version": 1,
    "content": [
      {
        "type": "paragraph",
        "content": [
          {
            "text": "This is a comment edited from PUT",
            "type": "text"
          }
        ]
      }
    ]
  }
}

I tested this specific API on Postman and I am unable to POST as I get a 405 Method not Allowed back.

What status are you getting back from the response? You seem to be catching it and logging it to the console.

Do you have the write:jira-work scope defined in the permissions of your manifest? https://developer.atlassian.com/platform/forge/manifest-reference/permissions/ as required by the API https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-id-put

Additionally, you’re making this call asApp() if any of the following is set against the issue you may only be able to update using the asUser() method:

Permissions required:

  • Browse projects project permission

  • for the project that the issue containing the comment is in.

  • If issue-level security

  • is configured, issue-level security permission to view the issue.

  • Edit all comments project permission

  • to update any comment or Edit own comments to update comment created by the user.

  • If the comment has visibility restrictions, the user belongs to the group or has the role visibility is restricted to.

Let me know if any of this was helpful.

Thanks for the quick Response! I’ve seemed to have found the problem and a temporary solution. So my bodyData came into the function as ADF properly and I also had the write:jira-work scope. The problem I had was that there wasn’t permission to edit all comments for the App so I set the permission to all logged in users which allowed the PUT call to work. This however is not desirable for my case as I don’t want just anyone to be able to edit all comments. Is there a way to just give permission to edit all comments to just the App?

Also, when I do make the REST API call it doesn’t properly return the response as none of the console logs I have returned anything for some reason but still performs the call? All the code after the REST API call under the dotted line doesn’t run either since the response.status will never be 800 but the code doesn’t throw

async function updateComment(issueId, commentId, bodyData) {
	console.log(`starting update`);
	const requestUrl = `/rest/api/3/issue/${issueId}/comment/${commentId}`;
	console.log(requestUrl);
	const newbody = {
	  "body": bodyData
	}
	
	const response = await api.asApp().requestJira(requestUrl, {
	  method: 'PUT',
	  headers: {
		'Accept': 'application/json',
		'Content-Type': 'application/json'
	  },
	  body: JSON.stringify(newbody)
	});
	
	---------------------------------------------------------------------------------
	
	console.log(`updateComment Response: ${response.status} ${response.statusText}`);
	 if (response.status !== 800) {
         console.log(response.status);
         throw `Unable to add comment to issueId ${issueId} Status: ${response.status}.`;
     }
     throw `Unable to add comment to issueId ${issueId} Status: ${response.status}.`;
	return(await response.json());
}

Is there a way to just give permission to edit all comments to just the App?