How can I adjust margins for a single section in Google Docs using Apps Script?

Attempting to set margins for one section changes the whole document. Code:

let reqPayload = {
  requests: [
    { insertSectionBreak: { sectionType: 'CONTINUOUS', location: { index: 1 } } }
  ]
};
Docs.Documents.batchUpdate(reqPayload, docKey);

let sectionElem = myDoc.getBody();
sectionElem.setMarginTop(5);
sectionElem.setMarginRight(5);
sectionElem.setMarginBottom(5);
sectionElem.setMarginLeft(5);

How can I restrict margin changes to a specific section?

sadly, google docs api doesnt let you set margins for just one section. margins apply to the whole document atm, so you might need to fake it with tables or separate docs as a workaround…

Based on my own attempts with the Google Docs API, there is currently no built-in functionality to apply margin changes to a single section using Apps Script. The API applies margin settings on a document-wide basis, which limits customization to individual sections. In my experiments, I found that workarounds like embedding content within a table or using additional documents were the only options available, though they add complexity. This API limitation has been consistent, so alternative design choices may be necessary for your specific layout requirements.