I’m working on a Chrome extension side panel. Part of it inserts text into a Google Doc open in Doc Picker as a paragraph style heading, like heading 2 for example.
I’ve been following the Google Docs API documentation and have tried using other example like the one here “/questions/70721569/how-add-styled-paragraphs-in-google-document-by-api”, “How add styled paragraphs in Google Document by API”, but without any luck. The only error I get is error status 15, and that is only sometimes.
The tags are either inserted as plain text or not inserted at all.
Here’s a simplified version of the code I’m using to insert the tags:
function insertIntoDoc(url, text, tags, insertionPosition, sendResponse) {
// ...
if (tags && tags.length > 0) {
tags.forEach(tag => {
requests.push({
insertText: {
text: `${tag}n`,
endOfSegmentLocation: {},
},
});
requests.push({
updateParagraphStyle: {
range: {
startIndex: -tag.length - 1,
endIndex: -1,
},
paragraphStyle: {
namedStyleType: 'HEADING_2',
},
fields: 'namedStyleType',
},
});
});
}
// ...
}
I’ve double-checked that I have the necessary permissions in the manifest.json file and that the OAuth2 setup is correct for accessing the Google Docs API. I know because it does insert the text, just not as a heading. Any help would be greatly appreciated. Thanks in advance any help or guidance you can give me!