//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get macro body by macro ID and convert representation Asynchronously
* Returns Async Id of the conversion task which will convert the macro into a content body of the desired format.
*/
export async function main(
auth: Confluence,
id: string,
version: string,
macroId: string,
to: 'export_view' | 'view' | 'styled_view',
expand: string | undefined,
allowCache: string | undefined,
spaceKeyContext: string | undefined,
embeddedContentRender: 'current' | 'version-at-save' | undefined
) {
const url = new URL(
`https://${auth.domain}/wiki/rest/api/content/${id}/history/${version}/macro/id/${macroId}/convert/async/${to}`
)
for (const [k, v] of [
['expand', expand],
['allowCache', allowCache],
['spaceKeyContext', spaceKeyContext],
['embeddedContentRender', embeddedContentRender]
]) {
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