Share Google Drive Folder via Zapier with Mailchimp trigger - google-drive-api

I can't figure out how to format the "Custom Value for Sharing Preference" on this Zap I'm trying to create that will share a Google Drive folder with my new Mailchimp subscribers.
I've been able to get the File ID using the Drive API, but I'm not sure how to provide the Custom Value that should come from the New Mailchimp Subscriber Email.
If I simply choose the Email address from the Mailchimp dropdown provided by Zapier and test it, I get an error:
We had trouble sending your test through. The app returned "The
permission type field is required.". This usually happens when your
Zap is missing a required field or a field value isn't in a recognized
format.
EDIT: Success via the Google Drive API test.
Using the sandbox available here, I know that I need to:
POST https://www.googleapis.com/drive/v3/files/fileId/permissions
the following Request Body
{
"role": "reader",
"type": "user",
"emailAddress": "email#example.com"
}
I've been able to run that test a few times with Google's sandbox, so I know I can do it. I just don't know how to pull this into Zapier.

Related

Make a Api Call with make.com and GoodBarber stuck

I would like to display information on Google Sheet, I have connected my GoodBarber API to my Google Sheet, however some data does not appear in the fields of Makes.com, I must therefore make a "Make a API Call" in order to get this information.
To do this, I installed this plugin, but I'm stuck on the code part for the API.
Here is a part:
Here is the feedback from the database, but the data that is not viisible on the sheet is:
"selected_delivery_slot": {
"date": "2025-04-15",
"slot_end": "08:40",
"slot_start": "08:30"
},
The configuration of the fields below are:
Can you help me please ?
Best regards,
I want with the Make.com solution to display all the data on a Google Sheet, but some data does not appear. So you have to call the "Make a API Call" module but I'm stuck at this step.

Access google sheet using google API key credentials

I was using google sheet from one application using htttp request like https://script.google.com/macros/s/XXXXXXXX/exec
but now Google has changed the access method. now I cannot access the URL mentioned above (XXXXXXXX : Replaced with my sheetid).
Now I was searching the access method and I found that we can also access using google API keys. which has to send in the HTTP request. Here is the page for more information.
https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps#httprest_1
But I am not getting a complete idea for HTTP request.
Anyone has tried the same or related.
From the question
I was using google sheet from one application using htttp request like https://script.google.com/macros/s/XXXXXXXX/exec but now Google has changed the access method. now I cannot access the URL mentioned above (XXXXXXXX : Replaced with my sheetid).
The XXXXXXXX is not the the sheetid, it's a unique id assigned to the corresponding web app deployment.
To get the web app full URL you have to go to your script, using the new Google Apps Script IDE, click on Deploy > Manage Deployments then select the corresponding deployment.
Resources
https://developers.google.com/apps-script/guides/web

A method to get The last Time a File was Opened in Google Drive

I need to get the last time a file was opened in Google Drive(Not Modified) via Apps Script.
I read the Docs but did not find anything similar. I do know that the last opened is being kept track of as it is available in Google Drive
I think there might be a way to add a Opened property to all the files in Drive but I am not sure how to implement it.
This would only be possible within a Workspace domain.
There is nothing in the Apps Script DriveApp as you have seen.
Even within the Drive API (accessible from Apps Script with the advanced services), the closest thing you have is:
{
"kind": "drive#file",
"id": string,
"createdDate": datetime,
"modifiedDate": datetime,
"modifiedByMeDate": datetime,
"lastViewedByMeDate": datetime,
"markedViewedByMeDate": datetime
}
So it will only get you the date that you viewed/opened it.
If all the users were within the same Workspace account, you can use service accounts. You would use the service account to impersonate all of the users and get the lastViewedByMeDate for each user.
A similar thing is possible with Aapps Script, but again within a Workspace Domain. Using the onOpen trigger, if you look at the event object there is the possibility to get the active user. Note that this will not work for Gmail accounts.
References
Advanced Services
Service Accounts
Event Object

Send message to Google Chat using the REST API (Google example not working in 2020)

Where do I even begin... (Google, why must you hurt me this way?)
Background Info
I have created a new chatbot using Google Apps Script, which receives messages from users in Google Chat and responds synchronously with a single message (each message can only have one response from the chatbot).
Now I need a way to send asynchronous messages so that the bot can send messages on its own, or send multiple separate responses at a time.
The problem
The Google Chat REST API has a method to create a message asynchronously, but this method (spaces.messages.create) does not work! There are no working examples of this method from 2020.
Here is Google's example code for creating a message using the REST API.
The problem is that in their example, the SCOPE is set to a URL that no longer exits:
var SCOPE = 'https://www.googleapis.com/auth/chat.bot';
If you navigate to that URL, you will see this 404 error:
Not Found
Error 404
Furthermore, if you check the list of available OAuth2 scopes, you will notice that there are no scopes related to Hangouts or Chat, and there is no mention of the chat.bot the scope which was used in the example code.
What have I tried?
I have read through every question on StackOverflow that is related to this Chat API, plus every tutorial for the REST API.
The official Apps Script tutorial from Google does not work because the chat.bot scope no longer exists:
Async Messages using Apps Script
These StackOverflow solutions all make use of the same non-existant chat.bot scope:
Send private message without event
Asynchronously Respond in new Hangout Chat using rest API
404 truncated server response on Apps Script Bot
This StackOverflow user says they were able to use the chat scope (i.e. googleapis.com/auth/chat), but that scope does not exist either:
Error 400: invalid_scope
In conclusion
How to send messages from Google Apps Script to Google Chat using the Google Chat REST API?
It seems that Google's documentation is outdated, and none of the examples for this API work as of August 2020. They are either unaware that their REST API does not work, or they deprecated the REST API without telling anyone.
Answer:
I can confirm that the chat.bot scope does indeed exist. To set up a chat bot with the REST API, you must use a service account.
More Information:
As per the documentation you linked on Developing bots with Apps Script, for sending async messages on trigger:
...the only way to achieve this currently is via the external HTTP API (see documentation). This requires the use of a Cloud service account (see documentation) via the OAuth2 for Apps Script library.
This means, that you must first set up a service account in the GCP console so that the chat.bot scope can be used for these messages. The whole process can be quite arduous for the unintitiated, so I will provide the steps from start to finish here.
The Process:
Creating a Service Account:
Navigate to the Google Cloud Console and create a new GCP Project. Hit Select a project at the top of the page and click NEW PROJECT.
You will need to provide a Project name, the other fields should be filled out for you automatically.
Press CREATE - a new pop-up will appear in the top-right of the screen confirming that a new project is being created. Once loaded, you can click VIEW.
Click the ☰ icon in the top-left, and follow the APIs & Services > Credentials menu item.
At the top of this page, click + CREATE CREDENTIALS > Service Account.
Give the service account a name and a description, and press CREATE, followed by CONTINUE, and finally DONE.
Your service account has now been created.
Creating Service Account Credentials:
These will be needed for the code provided in the example from the Developing bots with Apps Script page.
After creating the Service Account, you will be redirected back to the list of Credentials you can use for the GCP Project. Under the Service Accounts section, click you newly-created service account. This will be called service-account-name#project-name-XXXXXX.iam.gserviceaccount.com
Click ADD KEY > Create new key
Keep JSON selected, and press CREATE.
This will initiate a download of a credentials file which you will need to use to access the API as this service account. DO NOT LOSE OR SHARE THIS FILE. If lost, you will need to delete and create new credentials for this account.
Enabling the Hangouts Chat API:
Going back to ☰ > APIs & Services, and select Library.
Search for Hangouts Chat API and click the only result.
Click ENABLE. This will enable the API for your project.
Note: Do not close this tab yet! We will still need to use the GCP console later.
Setting up the Apps Script Project:
Create a new Apps Script project.
Now, you can copy + paste the example from the Async messages page into the new project.
Open up that credentials file that you downloaded from the GCP console.
Copy the private_key value (the one that starts with -----BEGIN PRIVATE KEY----- and paste it into value of SERVICE_ACCOUNT_PRIVATE_KEY in the Apps Script project.
Also copy the client_email value from the credentials file, and paste it into the SERVICE_ACCOUNT_EMAIL in the Apps Script project.
In order to use the Google Apps Script OAuth2 library as in the example, you will need to add the library to the project using the library's script ID.
In the Apps Script project UI, follow the Resources > Libraries... menu item, and copy paste the OAuth2 script ID into the Add a library box
The script ID is 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF
This, and the rest of the library can be found on the the OAuth2 for Apps Script GitHub repository
Make sure to select the latest stable version of the library (at time of writing, this is version 38)
Press Save.
Next, you will need to link the Apps Script project to the GCP project you created earlier.
Go back to the GCP Console tab, and follow the ☰ > IAM & Admin > Settings menu item.
Copy the Project number defined on this page.
In your Apps Script Project, follow the Resources > Cloud Platform project... menu item, and paste the Project number into the Enter Project Number here dialog.
Click Set Project.
Setting up the Project Manifest:
In order to use a chat bot in Apps Script, you must include the chat key in the project's manifest.
In the Apps Script UI, click View > Show manifest file.
After the last key-value pair, add the following:
"chat": {
"addToSpaceFallbackMessage": "Thank you for adding me!"
}
Your full manifest file will now look something like this:
{
"timeZone": "Europe/Paris",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Drive",
"serviceId": "drive",
"version": "v2"
}],
"libraries": [{
"userSymbol": "OAuth2",
"libraryId": "1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF",
"version": "38"
}]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"chat": {
"addToSpaceFallbackMessage": "Thank you for adding me!"
}
}
Save your project.
Final Steps:
You're nearly done! Now, you will need to deply the bot from manifest, and set up the configuration in GCP and set up the trigger which will make the actual call.
Deploying the bot:
In the Apps Script UI, go to Publish > Deploy from manifest... and hit Create in the newly opened dialog.
Note: You can not use the Head deployment if you want to use this for your whole domain, so a new deployment must be created.
Give the deployment a name and description, and press Save.
Once this has finished saving, press Get ID next to the deployment you just created, and copy the Deployment ID.
Setting up GCP configuration:
Going back to the Cloud console, you will need to now navigate to ☰ > APIs & Services > Dashboard.
In the list of enabled APIs at the bottom of this page, select the Hangouts Chat API.
On the left menu, select Configuration.
Set up your bot configuration. You will need to provide a Bot name, Avatar URL, and Description. Set up the functionality settings so that it works in rooms.
Under Connection Settings, select Apps Script project, and paste in your deployment ID from the previous section.
Give your Apps Script bot the relevant permissions, and press Save.
The Elusive Trigger:
The only thing you now need to do is set up your trigger. This is done like a normal Apps Script trigger - from the Edit > Current project's triggers menu item in Apps Script. To complete the example, click the + Add Trigger button in the bottom right and set up the trigger settings as follows:
Choose which function to run: onTrigger
Choose which deployment should run: Head
Select event source: Time-driven
Select type of time based trigger: Minutes timer
Select minute interval: Every minute
And press save.
And you're done! This created bot will now post to all rooms that it is in the current time, every minute.
References:
Service accounts | Cloud IAM Documentation
Understanding service accounts | Cloud IAM Documentation
Developing bots with Apps Script | Google Chat API | Google Developers
Bot-initiated messages - Creating new bots | Google Chat API | Google Developers
GitHub - gsuitedevs/apps-script-oauth2: An OAuth2 library for Google Apps Script.
Google Cloud Console

Transfer Ownership of Google Sheets from Service Account to General Account

I created a Google sheet using Google Sheets API which copied the content of spreadsheet present in one of my folder in Google Drive. Even the copied file did contain the code of App Script in it. So the file which was created using service account didn't allowed me to use the code of App Script. It throws the following error as shown in image below:
When I created the copy of this file from front end as shown in image below:
In this case owner was not service account so I was able to use the App Script.
Can any one help me with this?
You can programmatically make a Permissions.List using the service account credentials to make another user the owner of the file (the Spreadsheet in this case, you need its ID), you need to set the transferOwnership attribute to true and use a request body like this:
{
"role": "owner",
"type": "user",
"emailAddress": "new-owner#email.com"
}