//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Add labels to a space
* Adds labels to a piece of content. Does not modify the existing labels.
Notes:
- Labels can also be added when creating content ([Create content](#api-content-post)).
- Labels can be updated when updating content ([Update content](#api-content-id-put)).
This will delete the existing labels and replace them with the labels in
the request.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
Permission to update the content.
*/
export async function main(
auth: Confluence,
spaceKey: string,
body: { prefix: string; name: string }[]
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}/label`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago