Lucas Lima
Lucas Lima

Reputation: 902

How to send a custom message when adding a viewer to Google Spreadsheet via Google Apps Scripts?

I'm trying to add a viewer to a Google Spreadsheet via Google Apps Scripts, and, while doing so, also send a custom message like "Hi there! I'm sending this to you becase X, Y and Z".

I've already seen this question here on SO related to silencing the email when adding an Editor, but I couldn't sort out how to modify it so I can send a custom message.

What I'm trying:

Drive.Permissions.insert({'value': "[email protected]",
                        'type': "user",
                        'role': "reader",
                        'emailMessage': "Random text"
                        },
                       'mySpreadsheetKey');
}

I expected the "emailMessage" to work for that purpose, as stated in the Drive API docs. But, considering the parameters, I can see that that one specifically is not included in the request body, but, rather, on the parameters list, so I'm not sure about what to do.

Upvotes: 0

Views: 310

Answers (1)

Lucas Lima
Lucas Lima

Reputation: 902

Just as I was finishing my post, I figured it out. It turns out that, in the final section of the Advanced Drive Service docs, it is not specified, but, apparently, the request parameters should be sent as a third parameter, instead of sent inside the request body. So, my code turned out to be:

Drive.Permissions.insert({'value': "[email protected]",
                        'type': "user",
                        'role': "reader"
                        },
                       'mySpreadsheetKey',
                       {'emailMessage': "Random text"});

I decided to leave the question so it could help others, given the fact that I couldn't find a similar post.

Upvotes: 4

Related Questions