Start a workflow from Google Drive events
To run a workflow when Google Drive reports that a file or a user’s files changed, add a Webhook block whose Source is Google Drive and name its URL in a Drive notification channel. Drive posts one message per request. Each message starts its own run.
A message has no body. Its headers say that something changed and on which channel. The run asks Drive what changed with an HTTP request block.
You need a way to call the Drive API as the Google Account whose files you want to watch, and edit access to the workflow’s project. Google has no screen for notification channels: you create one with an API call.
Add the Webhook block and generate its URL
Section titled “Add the Webhook block and generate its URL”- In a draft workflow, add a Webhook block. The block palette also lists Google Drive webhook in the Start group, which adds the block with its source already set.
- Under Source, choose Google Drive. The line under the setting reads “Checks the credentials the sender repeats · one run per event · skips duplicates”.
- Under Webhook URL, select Generate URL, then copy the URL.
The badge beside the URL reads “Runs start after publish”. The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.
Choose a channel token and save it
Section titled “Choose a channel token and save it”Google does not sign a channel’s messages. What shows that a message came from your channel is the channel token: a value you choose when you create the channel, which Google then repeats in every message of that channel. OutWin compares it with the value saved on the block.
- Make up a long random value of up to 256 characters. Treat it as a password.
- In OutWin, paste it into Channel token in the block’s settings and select Save.
- Keep the value for the next section.
Save the token before you create the channel. Google sends the channel’s first message when the channel is created. Its documentation says that message can arrive before the call that creates the channel returns.
After you save, the settings show only the last four characters of the token. Replace and Remove appear beside them. Under Set up, the second line changes to “The channel token is saved: deliveries are verified.”
OutWin saves the token on the block’s URL. It is not saved on a connection. A second Webhook block has its own URL and its own token.
Without a saved token the block still starts runs, and nothing is checked: anyone who has the URL can start the workflow. Publishing then shows a warning that ends “has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow”. The warning does not block publishing.
The check shows only that the sender knows the token. A message carries no signature and no time, so anyone who learns the token and the URL can start a run. A message holds no data, and the run reads from Drive with the workflow’s own connection, so such a run reads only what that connection can read.
Create the channel with Drive’s API
Section titled “Create the channel with Drive’s API”Drive has two kinds of channel. A changes channel reports every change to the files the account can see. A file channel reports changes to one file.
- For a changes channel, send a
GETrequest tohttps://www.googleapis.com/drive/v3/changes/startPageTokenand keep thestartPageTokenit returns. It marks the present point in the account’s list of changes. - Send a
POSTrequest tohttps://www.googleapis.com/drive/v3/changes/watchwith that value as thepageTokenquery parameter. For a file channel, send it tohttps://www.googleapis.com/drive/v3/files/{fileId}/watchinstead, with the id of the file in place of{fileId}. - In the request body, set
addressto the URL you copied,tokento the value you saved,typetoweb_hook, andidto a value of your own that no other channel has used. - Set
expirationto the moment the channel ends, as Unix time in milliseconds.
For example:
{ "id": "<a unique value of up to 64 characters>", "type": "web_hook", "address": "<the block's URL>", "token": "<the token you saved>", "expiration": 1795942800000}Send the request from any tool that can call the Drive API as that account. An HTTP request block can send it too, within the limit on its credential described under Read the message and fetch the changes. OutWin does not create the channel for you.
Google answers with the channel, including a resourceId. Keep the id and the resourceId. Google’s call that stops a channel, https://www.googleapis.com/drive/v3/channels/stop, asks for both.
When the channel is created, Google sends one sync message to the URL. Recent deliveries lists it as Ping with “A ping from the sender, not an event. Nothing ran.” The last line under Set up then reads “Received sync. Ping.” The ping shows that Google can reach the URL and that the token matches. It starts no run.
Replace the channel before it expires
Section titled “Replace the channel before it expires”A Drive channel ends at its expiration. Google then sends nothing more, and no run starts. OutWin does not renew a channel. Google’s documentation says a channel cannot be renewed, only replaced with a new one.
Google sets the longest lifetime by the kind of channel: one day for a file channel and one week for a changes channel. A channel created without expiration ends after one hour.
To keep messages coming, create a new channel before the old one ends, on a schedule of your own. Give it a new id, the same address, and the same token. Google’s documentation says the old and the new channel can both be active for a time. One change can then arrive on each channel. Each message starts a run.
When a channel has an expiry, each of its messages says when it ends, in the x-goog-channel-expiration header.
Choose which events start a run
Section titled “Choose which events start a run”Under Events that start a run, tick the types that start a run. The block offers change, changed, add, update, remove, trash, and untrash. With none ticked, every message except sync starts a run. To start runs for a type that is not listed, type it into the box under the list and select Add.
The type is the state Google reports in the message. Google’s documentation says a changes channel sends change, and its own example of that message shows changed. Tick both or neither. A file channel sends add, update, remove, trash, or untrash. Google’s documentation says it can add states over time.
A message whose type is not ticked is listed as Filtered out and starts no run. To narrow further, add a row under Only when. A message has no body, so a row reads a header. For example, a row with the field headers["x-goog-changed"], the comparison contains, and the value content starts runs only when a file’s content changed. Google sends that header on some update messages of a file channel. Webhook settings lists the comparisons.
Send a test and check what arrived
Section titled “Send a test and check what arrived”- Cause a change the channel watches. For a changes channel, rename a file in that account’s Drive.
- In OutWin, look under Recent deliveries in the block’s settings.
Recent deliveries lists every message that reached the URL, including while the workflow is a draft. On a draft each message other than sync is listed as Dropped with “The workflow is not published, so nothing ran.” It starts no run and is not run later. The last line under Set up changes from “Received sync. Ping.” to, for example, “Received change. Dropped.”
With a token saved, a message listed as Dropped on a draft has passed the check. A request that fails the check is listed as Refused.
If you have edit access, select a message to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.
Read the message and fetch the changes
Section titled “Read the message and fetch the changes”Each run receives one message. An HTTP request block or a database block directly after the Webhook block reads it with these expressions. An AI block such as Think receives the whole value as its input.
| Expression | What it holds |
|---|---|
{{input.body}} |
Empty. A Drive message has no body. |
{{input.event.type}} |
The state Google reports, such as change or update. It is the request’s X-Goog-Resource-State header. |
{{input.headers["x-goog-channel-id"]}} |
The id you gave the channel. Header names are lowercase. |
{{input.headers["x-goog-resource-id"]}} |
Google’s id for what the channel watches. It is the resourceId in the answer to the watch request. |
{{input.headers["x-goog-resource-uri"]}} |
The address of what the channel watches in the Drive API. |
{{input.headers["x-goog-changed"]}} |
What changed about a file, as a list separated by commas, such as content,properties. Google sends it on some update messages of a file channel. |
{{input.event.id}} |
A value OutWin builds from the channel’s id and the request’s X-Goog-Message-Number header, because Google sends no single id for a message. |
{{input.event.time}} |
Empty. Google sends no time for a message. {{input.delivery.receivedAt}} holds the moment the request arrived. |
{{input.delivery.verified}} |
true only when the request carried the saved token. |
OutWin removes the token’s header before it stores a message or passes it on.
A block further along reads the same values through the Webhook block’s name, as in {{steps["Google Drive"].headers["x-goog-channel-id"]}} for a block named Google Drive. Data and context describes what each block passes on.
To get the changes, add an HTTP request block after the Webhook block. It needs an API connection whose credential Google accepts for that account. OutWin does not sign in to Google and does not refresh an access token. A Google access token expires after about an hour, so you need your own way to supply a current one, for example a service of your own in front of Google’s API.
For a changes channel, set the block to send a GET request to /drive/v3/changes, under the host https://www.googleapis.com, with the query parameter pageToken. Google answers with a list named changes. When the list is complete, the answer also holds newStartPageToken, which is the value for the next call. Keep it between runs, for example in a database, and start with the startPageToken you fetched before you created the channel. A run that passes an older value reads changes that earlier runs already read.
For a file channel, send a GET request to /drive/v3/files/ followed by the file’s id, which you know from creating the channel.
Publish and check the runs
Section titled “Publish and check the runs”Publish the workflow. From then on, each message that passes the filter starts a run. On a published workflow the block’s settings are read-only, and Recent deliveries is in the block’s inspector. You can still replace the token there.
| Outcome | What happened |
|---|---|
| Ran | The message started a run. |
| Waiting | 10 runs of the workflow are already active. The message starts a run when one of them ends. A message that waits longer than an hour is listed as Dropped. |
| Duplicate | A message with the same channel id and message number already ran in the last 72 hours. The line reads “This event was already received and run, so it did not run again.” |
| Ping | Google’s sync message when a channel was created. It starts no run. |
Google’s documentation does not say whether a message it sends again keeps its message number. If it does not, the repeat starts a second run. A run that lists changes from the saved page token reads nothing twice.
Runs start in the order messages arrive. That is not always the order things happened, so do not build a workflow that relies on add arriving before update.
Receiving a message costs no credits, and neither does one that is filtered out, a duplicate, or a ping. A run that starts uses credits for the blocks that run in it.
If nothing runs
Section titled “If nothing runs”Open Recent deliveries and read the outcome and the sentence beside the newest message.
| What you see | Cause | Fix |
|---|---|---|
| “Nothing has arrived yet.” | No request has reached the URL, not even sync. |
Check that the watch request succeeded and that its address is the block’s current URL. Rotate token on a published workflow changes the URL, and the old one stops working: create a new channel with the new one. |
| Ping and nothing else | Google created the channel, and nothing it watches has changed since. | Cause a change to what the channel watches, in the account the channel was created for. |
| Messages arrived for some hours or days and then stopped | The channel reached its expiration. A channel created without one ends after one hour. |
Create a new channel with a new id, the same URL, and the same token, and replace it before it ends. |
| Dropped with “The workflow is not published, so nothing ran.” | The workflow is a draft. | Publish the workflow. Messages that arrived before then are not run later. |
| Dropped with “The workflow is paused, so nothing ran.” | The workflow is paused. | Resume the workflow. Messages that arrived while it was paused are not run later. |
Filtered out with Events of type "changed" are not chosen on this trigger. |
The message’s type is not ticked under Events that start a run. | Tick the type, or clear every tick so that all messages start a run. The settings are read-only on a published workflow. |
| Refused with “The value the request carried did not match the one saved here.” | The channel was created with a token that is not the saved value. |
Select Replace and save the token the channel was created with, or create a new channel with the saved token. You do not republish the workflow. |
| Refused with “The request did not carry the value this trigger expects.” | A token is saved in OutWin, and the request carried none. The channel was created without token, or the request was sent by hand to try the URL. |
Create a new channel whose token is the saved value. |
A request listed as Refused is answered with status 401 and starts nothing. OutWin keeps none of its data. For every other outcome in the table, Google receives a success response and OutWin does not run the message later.