//native
/**
* Create Blog Post
* Create a new blog post in a space. The body is supplied as a content string in the chosen representation (default "storage", i.e. Confluence storage HTML).
*/
export async function main(
auth: RT.Confluence,
space_id: string,
title: string,
body: string,
status: "current" | "draft" | undefined,
representation: "storage" | "atlas_doc_format" | undefined
) {
const base = auth.baseUrl.replace(/\/$/, "")
const url = new URL(`${base}/wiki/api/v2/blogposts`)
const payload = {
spaceId: space_id,
status: status ?? "current",
title,
body: {
representation: representation ?? "storage",
value: body,
},
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Basic " + btoa(`${auth.email}:${auth.apiToken}`),
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(payload),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago