Edits history of script submission #22822 for ' Create Page (confluence)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Page
     * Create a new page 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,
      parent_id: string | undefined,
      representation: "storage" | "atlas_doc_format" | undefined
    ) {
      const base = auth.baseUrl.replace(/\/$/, "")
      const url = new URL(`${base}/wiki/api/v2/pages`)
    
      const payload = {
        spaceId: space_id,
        status: status ?? "current",
        title,
        parentId: parent_id,
        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