//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get user
* Returns a user. This includes information about the user, such as the
display name, account ID, profile picture, and more. The information returned may be
restricted by the user's profile visibility settings.
**Note:** to add, edit, or delete users in your organization, see the
user management REST API.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
Permission to access the Confluence site ('Can use' global permission).
*/
export async function main(
auth: Confluence,
accountId: string | undefined,
expand: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/user`)
for (const [k, v] of [
['accountId', accountId],
['expand', expand]
]) {
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