//native
/**
* Insert Page Break
* Insert a page break into a Google Doc's body at a character index, or at the end when `index` is empty. Set `tab_id` (from List Tabs) to target a tab other than the first.
*/
export async function main(
auth: RT.Gdocs,
document_id: string,
index: number | undefined,
tab_id: string | undefined
) {
const tabId = tab_id || undefined
const response = await fetch(
`https://docs.googleapis.com/v1/documents/${document_id}:batchUpdate`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ requests: [{
insertPageBreak:
index == null
? { endOfSegmentLocation: { tabId } }
: { location: { index, tabId } },
}] }),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 hours ago