//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get content in space with given content state
* Returns all content that has the provided content state in a space.
If the expand query parameter is used with the `body.export_view` and/or `body.styled_view` properties, then the query limit parameter will be restricted to a maximum value of 25.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
'View' permission for the space.
*/
export async function main(
auth: Confluence,
spaceKey: string,
state_id: string | undefined,
expand: string | undefined,
limit: string | undefined,
start: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}/state/content`)
for (const [k, v] of [
['state-id', state_id],
['expand', expand],
['limit', limit],
['start', start]
]) {
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