Trigger an automation from Google Apps Script with sheet data

How to trigger an automation from Google Apps Script with sheet data: install the Chrome extension, click Build with Browser agent, tell the agent what you want, and follow its prompts. A working bot is built and tested in minutes.

Here is how the automation works. To trigger an automation from Google Apps Script, send a POST request to the axiom.ai trigger endpoint with your API key, the automation's name and the sheet's rows. In the automation, a Receive data from another app step holds the rows, and the steps after it use them: the example here sends every row of the active Google Sheet and types the text from column A into Google search.

Author
Alex Barlow
Published

Build the Google Apps Script trigger from a description


Describe it and click the button: the agent builds and tests the automation in your Chrome extension. You need your API key from the Dashboard, see authentication.

  1. Take the rows my Apps Script sends me
  2. Open Google search
  3. Type the text from column A into the search
Click to launch the Chrome extension. Not installed? You can create an account and try it free.Opens the Chrome extension. Free account to try.

You need a Google Sheet with some text in column A. The Apps Script that sends the rows is added to the sheet by you, once the automation is saved and you have its exact name: see how to add the Apps Script to the Google Sheet.

The video shows the agent building the Google Apps Script trigger from the three lines above, in a few minutes.

Build the Google Apps Script trigger step by step


The steps the agent builds, as the Builder shows them: each step by its name, with the fields to set under it. Add them yourself in this order in the step-by-step builder, or open the agent's result there to adjust it.

  • 1.0 Receive data from another app
  • 2.0 Go to page
  • 3.0 Enter text
    • Select text field: the search field
    • Text: column A of [webhook-data]

Common questions about the Google Apps Script trigger


How do I add the Apps Script to the Google Sheet?

In the Google Sheet, click Extensions > Apps Script, paste the script below, replace Insert key here with your API key and Insert automation name here with the automation's name, copied from the Dashboard since it is matched exactly. Save the script with the disc icon and run sendDataToAxiomAi with the play icon; when the request works, the execution log shows the link axiom.ai returns to view the run.

function sendDataToAxiomAi() {
  var url = 'https://lar.axiom.ai/api/v3/trigger'; // The axiom.ai trigger endpoint
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var dataValues = sheet.getDataRange().getValues(); // Every row of the sheet, as a 2D array

  var payload = {
    "key": "Insert key here",
    "name": "Insert automation name here",
    "data": dataValues // Sent as an array of rows
  };

  var options = {
    'method': 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(payload)
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    Logger.log(response.getContentText());
  } catch (error) {
    Logger.log('Error: ' + error.toString());
  }
}

How do I trigger the automation whenever the Google Sheet is edited?

Add an Apps Script trigger on edit.

  1. Click Triggers in the Google Apps Script sidebar.
  2. Click Add Trigger.
  3. Set the function to run to sendDataToAxiomAi and the event type to On edit.
  4. Click Save.

The script then sends all the sheet's data each time a cell changes. Add your own checks to the script if only some edits should trigger a run.

The log names the problem. Task not found, please check the name and try again. means the automation name does not match exactly, and Invalid key means the API key is wrong. The trigger endpoint page lists every response.

Can I send only some of the sheet's rows to the automation?

Yes. dataValues in the script is every row of the sheet; filter that array before it goes into payload, for example to the rows with a value in a given column, and the automation receives only those.

Can I trigger an automation from a Google Sheet without code?

Yes, when the automation reads the sheet itself. The Google Sheets integration reads, writes and edits sheet data with no code; Apps Script is for starting the run from the sheet itself.

Can I trigger an automation the same way from other apps?

Yes. Any app that can send a POST request or call a webhook can start a run the same way. For Zapier, see automate data entry into a web form from Zapier.

Where do I get help?

Get in touch with support, or ask in the axiom.ai community.

Related guides