0

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?

VladTbk321
  • 73
  • 8
  • This link may may assist... https://stackoverflow.com/a/69727327/1533592 – dale landry Apr 02 '23 at 19:59
  • "a post request to a Google Document to insert some text." You have not given a full description of your scenario, nor the text that you want to insert, nor any sample data nor an example of a successful outcome. Please create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Tedinoz Apr 03 '23 at 01:35
  • Whenever possible, you need to include a minimal example that reproduces the issue. You can also include the expected behavior, the actual behavior, and how they differ, that would be helpful as well. Please visit [How to Ask](https://stackoverflow.com/help/how-to-ask) have some tips on how to write a question, so the community will be able to help you out in a better way. – Giselle Valladares Apr 03 '23 at 12:15
  • I've updated the question, sorry for confusion! – VladTbk321 Apr 03 '23 at 13:37

0 Answers0