//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Create user property by key
* Creates a property for a user.
*/
export async function main(auth: Confluence, userId: string, key: string, body: { value: {} }) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/user/${userId}/property/${key}`)
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.text()
}
Submitted by hugo697 235 days ago