Remove watch Auth issue

Hello,
Can anyone help me understand how to configure the X-Atlassian-Token to manage page watches?
The reference docs don’t go into the details of how to do it → Remove watch
The function I use is this:

	const response = await api
		.asUser()
		.requestConfluence(route`/wiki/rest/api/user/watch/content/${page}`, {
			method: "DELETE",
			headers: {
				Accept: "application/json",
				"X-Atlassian-Token": "no-check",
			},
		});

	console.log(`Response: ${response.status} ${response.statusText}`);
	console.log(await response.text());

In this case I still get an error

[NEEDS_AUTHENTICATION_ERR: Authentication required] {
  serviceKey: 'atlassian-token-service-key',
  status: 401
}

Instead if I use “asApp” although I get a 204 answer nothing changes in the page watch.
Thanks!

Just stabbing in the dark. Have you checked that the user of the app has the proper Space Permissions and Page Restrictions? It looks like when trying asApp you might be getting a 204 because the app has permissions, but since you aren’t including an accountId, it “removes” that app’s user (which might not be a watcher)?

I don’t have any experience with X-Atlassian-Tokens but if you are getting a legitimate 204, a workaround might be to pass the current user ID and performing asApp, instead of performing asUser. It might depend on if it is something the App just does, or if it is something triggered by the user, and if traceability matters whether or not this is okay. Again, just a thought, not sure if it would work.

2 Likes

:clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:

route`/wiki/rest/api/user/watch/content/${page}?accountId=${user}`,