I want to create an addon to automatically activate and deactivate the "Out of office or vacation reply". Therefore I need to add an UI element, where the users are able to setup their recurring weekly absences.
Is it somehow possible to add an addon to the sidebar, which does not require the selection of an email object to be shown? Or better, can I add a tab to the settings, where the parameters can be set?
I only found mail specific scopes for GMail addon development.
In the meantime I found a solution to avoid the need to click on a mail by changing the manifest file.
"addOns": {
"common": {
"name": "xyz",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
"useLocaleFromApp": true,
"homepageTrigger": {
"runFunction": "renderRootCard",
"enabled": true
},
Doing this, the main function is already triggered when opening Gmail itself.
Related
I try to publish an Editor Add-on for Google Sheet into the workspace marketplace.
But I'm struck on the review.
With this message :
The App doesn’t meet the publishing review criteria on the following:
Menu - Menu options not shown after App is installed. Please ensure that the add-on correctly uses onInstall() and onOpen() to populate its menu. The menu items populate when the add-on is first installed and when a different file is opened. See Editor add-on authorization.
My app does not have a menu, so I was thinking I must add one, in my index function.
Failed with same message.
So I add an onOpen(e) and onInstall(e) functions like the documentations.
And the review failed too.
So I don't know what to do.
My app is writed in AppScript
Here some code:
function menuItem1() {
SpreadsheetApp.getUi() /
.alert('You can contact me at ...');
}
function onInstall(e) {
onOpen(e);
}
function onOpen(e) {
SpreadsheetApp.getUi().createAddonMenu()
.addItem('Contact', 'menuItem1')
.addToUi();
}
function index(isConnected = false) {
var divider = CardService.newDivider();
.....
And here my appscript.json
{
"timeZone": "Europe/Paris",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/script.locale",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/script.external_request"
],
"urlFetchWhitelist": [
"myapi"
],
"addOns": {
"common": {
"homepageTrigger": {
"runFunction": "index",
"enabled": true
},
"logoUrl": "urltomylogo",
"name": "Name of my app",
"useLocaleFromApp": true
},
"sheets": {}
}
}
My app has successfully passed the oAuth verificaton by Google.
And now I'm stuck on the publishing
Help is appreciated,
Thx
Edit - Solution.
Indeed, the addon was on Editor add-on mode, I switched it to Google Workspace Addon and it worked.
Thx
Apparently you have confussed Workspace Add-ons with Editors Add-ons or viceversa. Both might be created using Google Apps Script, the way to publish them is very similar, on the first you will use the deployment ID on the second, instead you will the project version number. Another difference about these add-ons types is that an Editor Add-on can't use the CardService, it's only available for Workspace Add-ons, while Workspaces Add-ons can't use the onOpen simple trigger among other things.
Please review the details about the differences between Workspace Add-ons and Editors Add-ons on https://developers.google.com/apps-script/add-ons/concepts/types, and review carefully the publishing docs:
https://developers.google.com/apps-script/add-ons/how-tos/publish-add-on-overview?hl=en
https://developers.google.com/workspace/marketplace/enable-configure-sdk
Since you are trying to publish an Editor Add on you should check the Authorization model that these type of Add ons need, not having a proper menu for your Add on will most likely be the main reason of it's rejection.
Checking the full lifecycle of these add ons should give you an idea of what you need to implement in your current state:
If an add-on is either installed for the current user or enabled in the current document, the add-on is loaded in the document, which causes it to appear in the Add-ons menu and start listening for the simple triggers onInstall(e), onOpen(e), and onEdit(e). If a user clicks one of the add-on’s menu items, it runs.
Reference:
The complete lifecycle of an Editor Add on
Google's documentation says that all URLs must be explicitly listed in urlFetchWhitelist.
However, I have a URL in universalActions and it works, even though I don't have the URL in urlFetchWhitelist. What am I misunderstanding?
{
"timeZone": "America/New_York",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [],
"addOns": {
"common": {
"universalActions": [
{
"label": "About",
"openLink": "https://github.com/imthenachoman/Gmail-Auto-Vacation-Responder"
}
]
},
"gmail": {},
"calendar": {}
}
}
As stated in the documentation:
Universal actions are menu item elements that allow a user to open a new web page, display new UI cards, or run a specific Apps Script function when selected. In operation they are very similar to card actions, except that universal actions are always placed on every card in your add-on, regardless of the current add-on context.
The scope of the Unversal Actions is already defined inside the appscript.json, so it would not make sense to include it again inside the urlFetchWhiteList. As you can read in the documentation:
Universal actions are configured in your add-on's project manifest. Once you've configured a universal action, it is always available to users of your add-on.
In short, Universal Actions are intended for actions that do not depend on the current execution context, and that are available from anywhere in the add-on. For any other type of request, for example, interacting with an external API, the urls of that API should be included in the urlFetchWhiteList.
I am using a tracker for my team to track their progress. At the beginning, I make duplicates of a mastersheet which has a code already in it. But If i want anything to be changed in the code, I will have to manually go to all sheets and make the changes. Is there a work around where I can change the code in all sheet if I change the code in my mastersheet?
Have you looked into libraries? https://developers.google.com/apps-script/guides/libraries
Using these concepts, you could publish a library and give all of those people edit access, then in the original spreadsheet access the library through development mode (or head deployment for the new IDE), and then they can get real-time updates to the code implemented in their script. This is best if it's ok to give edit access to the library to everyone; if it's view access only it's more complicated but still possible. Can provide an edit if you need to give view access.
Answer:
You can make changes to Apps Script code in other files using the projects.updateContent method of the Apps Script API.
More Information:
As per the documentation:
[This method] Updates the content of the specified script project. This content is stored as the HEAD version, and is used when the script is executed as a trigger, in the script editor, in add-on preview mode, or as a web app or Apps Script API in development mode. This clears all the existing files in the project.
In order to update code in other projects you must provide the enire script of all files, and not just the newly updated functions.
The request needs to be to:
PUT https://script.googleapis.com/v1/projects/{scriptId}/content
and the request body takes the form:
{
"files": [
{
"name": string,
"type": enum (FileType),
"source": string,
"lastModifyUser": {
"domain": string,
"email": string,
"name": string,
"photoUrl": string
},
"createTime": string,
"updateTime": string,
"functionSet": {
"values": [
{
"name": string
}
]
}
}
]
}
Remember that you must inclide the appsscript.json manifest file when using this endpoint.
References:
Method: projects.updateContent | Apps Script API | Google Developers
I wrote a function that adds an all-day event.
When the function running from script editor it's working fine, the all-day event is inserted to the calendar.
But when I'm running the function in the active spreadsheet =addevent(a1,b1,c1,d1)
I'm getting an error saying :
Exception: The script does not have permission to perform that action. Required permissions: (https://www.googleapis.com/auth/calendar || https://www.googleapis.com/auth/calendar.readonly || https://www.google.com/calendar/feeds) (line 11)
After searching the net I found how to add manually those permission by editing the oauthScopes in the JSON file:
{
"oauthScopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.google.com/calendar/feeds",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets"
],
"timeZone": "censored",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Calendar",
"serviceId": "calendar",
"version": "v3"
}]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
But I am still getting the same error in the spreadsheet...
Answer:
While it is not possible to run a script which requires authorisation directly from a cell in a Sheet, you can set up the script to run on button click instead.
More Information & Workaround:
As a button does not have the same authorisation restrictions as custom functions, you can use them to run code with the scopes you need. To set this up:
Go to the Insert > Drawing menu item and create a shape; any shape will do, this will act as your button.
Press Save and Close to add this to your sheet.
Move the newly-added drawing to where you would like. In the top-right of the drawing, you will see the vertical ellipsis menu (⋮). Click this, and then click Assign script.
In the new window, type whatever the name of your function is, without parentheses (for example myFunction), and press OK.
References:
Custom Functions in Google Sheets | Apps Script | Google Developers
That is because you are not allowed to use a custom function to perform actions that require authorization such as adding an event to your calendar.
From the official documentation:
Unlike most other types of Apps Scripts, custom functions never ask
users to authorize access to personal data.
However, there are some workarounds that you could try. For example, you can create a custom menu option within your spreadsheet file or a time-driven trigger.
I am just starting to try building a new Gmail Add-on, and am running into the following error message:
"You do not have permission to call fetch"
This happens when testing the add-on in the Script Editor, and also when deployed inside my Gmail. Here is a sample of the code:
function getContextualAddOn(e) {
var API_KEY = 'TESTKEY';
var URL = 'https://[REDACTED]';
var options = {
'method' : 'post',
'contentType': 'application/json',
'headers': {
'x-api-key': API_KEY
},
'payload' : JSON.stringify({ 'foo': 'bar' })
};
var response = UrlFetchApp.fetch(URL, options);
[more code that builds a card]
}
As you can see, it's a pretty straightforward use of UrlFetchApp.fetch. I'm brand new to Apps Script, so maybe I am missing some permissions declaration or scope in my manifest. I tried an even simpler example just using UrlFetchApp.getRequest, but that also failed with "You do not have permission to call getRequest".
The manifest for the addon is the same as in the examples:
{
"timeZone": "America/New_York",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
"https://www.googleapis.com/auth/userinfo.email"
],
"urlFetchWhitelist": [
"https://[REDACTED]"
],
"gmail": {
"name": "Test Add-On",
"logoUrl": "some url",
"primaryColor": "#4285F4",
"secondaryColor": "#4285F4",
"contextualTriggers": [{
"unconditional": {},
"onTriggerFunction": "getContextualAddOn"
}],
"version": "TRUSTED_TESTER_V2"
}
}
Is UrlFetchApp supposed to be allowed inside a Gmail Add-On, or is this just a bug? Do I need to add something to my manifest or enable some other option in the script editor?
The UrlFetchApp service requires an additional scope, https://www.googleapis.com/auth/script.external_request. Add it to your list of scopes and the code should work.
The scopes required for each Apps Script method is listed under the "Authorization" section in the reference docs (example). Alternatively, you can discover the scopes required by your script by temporarily removing the oauthScopes section of the manifest and viewing the auto-determined scopes for your code in File > Project properties > Scopes. (If you define any scopes in your manifest, this disables the "automatic scope detection" behavior of Apps Script.)
References
Setting Scopes
Manifest File
All Google Scopes
The accepted answer was from 2017. I don't know if Google has changed its authorization policy since then, but simply adding a new scope to the Project Properties settings won't work.
How do you trigger the function that call fetch?. You can't use simple triggers to do that. They fire automatically, so they can't access services that require authorization. UrlFetchApp definitely requires permission. There is no way to open a dialog to ask for users' content with simple triggers.
You, as the script owner, can add new authorization scope, but what happens when you deploy this script with end users? How are they going to grant their permission to the script to make API calls to some unfamiliar servers?
To get around this, you need to use installable triggers. Whatever are available in simple triggers, there are equivalent in installable triggers.
Let's assume that you want to call the API on opening the spreadsheet.
From the Script Editor, go to Edit >> Current Project's Triggers and set up a new trigger.
Under Run, select the name of the function that you want to trigger. In the OP's case, it's the getContextualAddOn(e) function.
Under Select event source, choose From spreadsheet.
Under Event type, choose On Open.
Configure other settings as you like and save.
Use installable trigger instead and write your own function that you bind to your installable trigger.
https://developers.google.com/apps-script/guides/triggers/installable#g_suite_application_triggers
This solved the issue for me.