I am currently sending a post request to a Google Document to insert some text. This is how I do it:
const updateDoc = async (token, ID, requests) => {
const postLinkDocs = `https://docs.googleapis.com/v1/documents/${ID}:batchUpdate`;
try {
await fetch(postLinkDocs, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json',
},
body: JSON.stringify({
requests: requests,
}),
});
} catch (error) {
console.log('Batch update error:', error);
return false;
}};
Where my request looks like this:
const requests = {
insertText: {
text: word + ' ', // ' ' is used to add space
endOfSegmentLocation: {},
},
};
Where the text I am sending is from a Speach to Text API. It gets the words right on the docs, always appending to the previous text
|This was the first text and then it came the second
But my cursor doesn't update with it (the | represents the cursor postion, being stuck at the start). I also checked in Google Apps Script for its value and is always null.
const doc = DocumentApp.openById(docID);
const body = doc.getBody();
const cursor = doc.getCursor();
console.log(cursor) <- returned null even though cursor is displayed at the begging of the docs
Is there a way to update its position inside the request or in GAS?