//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Restore content version
* Restores a historical version to be the latest version. That is, a new version
is created with the content of the historical version.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
Permission to update the content.
*/
export async function main(
auth: Confluence,
id: string,
expand: string | undefined,
body: {
operationKey: 'restore'
params: {
versionNumber: number
message: string
restoreTitle?: false | true
}
}
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/version`)
for (const [k, v] of [['expand', expand]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
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