I have a google docs template and I would like to replace some strings from the template with external data, preferably via cURL as the script that should do the changes is a bash script.
I have the search and replace in google app script done like the one below but I don't know how to call the script and replace with some external data instead.
function myFunction() {
var doc = DocumentApp.openById("DOCUMENT_ID");
var body = DocumentApp.getActiveDocument().getBody();
var client = {
name: 'Some name',
address: 'Some address'
};
body.replaceText('{name}', client.name);
body.replaceText('{address}', client.address);
}
UPDATE:
I created the following google apps script:
function doPost(e) {
var body = DocumentApp.openById("JYOfA_Uv5fxLFA84g11H9XsizHo3F7e1FvSs3EG1vvo").getBody();
var client = new Function("return " + e.postData.contents)();
body.replaceText('{name}', client.name);
body.replaceText('{address}', client.address);
return ContentService.createTextOutput("Done.")
}
The cURL command I'm running is:
curl -L -d '{"name":"hello","address":"world"}' 'https://script.google.com/macros/s/AKfycbxF_1gddelneCdWCsFcvqT1OgU2zqkjTKSEIulSQfXjfgx1rnY/exec'
And the document that the google apps script calls basically has the information {name} and {address}.
The cURL command gives me error that the file could not be found.
The links are accessible as there aren't anything secret there. Only test stuff.
UPDATE 2:
Link to the test document: https://docs.google.com/document/d/1JYOfA_Uv5fxLFA84g11H9XsizHo3F7e1FvSs3EG1vvo/edit