//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get label watch status
* Returns whether a user is watching a label. Choose the user by doing one
of the following:
- Specify a user via a query parameter: Use the `accountId` to identify the user.
- Do not specify a user: The currently logged-in user will be used.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
'Confluence Administrator' global permission if specifying a user, otherwise
permission to access the Confluence site ('Can use' global permission).
*/
export async function main(
auth: Confluence,
labelName: string,
key: string | undefined,
username: string | undefined,
accountId: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/user/watch/label/${labelName}`)
for (const [k, v] of [
['key', key],
['username', username],
['accountId', accountId]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago