//native
/**
* Search Content (CQL)
* Search for content using the Confluence Query Language (CQL), e.g. `type=page AND space=ENG AND text ~ "release notes"`.
*/
export async function main(
auth: RT.Confluence,
cql: string,
cursor: string | undefined,
limit: number | undefined,
expand: string | undefined
) {
const base = auth.baseUrl.replace(/\/$/, "")
const url = new URL(`${base}/wiki/rest/api/search`)
url.searchParams.append("cql", cql)
if (cursor !== undefined && cursor !== "")
url.searchParams.append("cursor", cursor)
if (limit !== undefined) url.searchParams.append("limit", String(limit))
if (expand !== undefined && expand !== "")
url.searchParams.append("expand", expand)
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.email}:${auth.apiToken}`),
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago