Skip to content

How to Write Google Form Responses to WorkHub24 Datastore

This guide explains how to automatically send Google Form responses to a WorkHub24 datastore via the datastore POST API using Google Apps Script. Follow these steps to set up and deploy the script.

Prerequisites

Before starting, ensure you have:

  • A Google Form created and ready to collect responses.
  • A WorkHub24 Datastore POST API endpoint and the necessary access credentials (Client ID & Secret).

Steps

  1. Open the Apps Script Editor

    1. Open your Google Form.

    2. Click on the Responses tab.

    3. Once you are directed to the Responses tab, if a Google Sheet is connected to the form, you will see the option to ‘View in Sheet’. Click on it. If no Google Sheet is connected, you need to create a new connection from this section.

    4. After being redirected to the Google Sheet, click on Extensions > Apps Script.

  2. Copy and Paste the Script

    1. Delete any existing code in the script editor.
    2. Copy and paste the following script:
function onFormSubmit(e) {
var formData = e.values; // Captures the submitted values
var url = '
https://app.workhub24.com/api/datatables/TENANT_ID/DATASTORE_ID/records
'; // Replace with your API endpoint
// Construct the payload from form data (adjust indices based on your form structure)
var payload = {
"customerName": formData[1], // Assuming 'Customer Name' is the first question after the timestamp, the key values should match the public field names in the WorkHub24 datastore.
"satisfaction": formData[2], // Adjust field mapping as needed
"comments": formData[3]
};
// Configure the options for the POST request
var options = {
method: 'POST',
contentType: 'application/json',
headers: {
'Authorization': 'Bearer ' + getAccessToken(),
'accept': 'application/json',
'Content-Type': 'application/json'
},
payload: JSON.stringify(payload) // Convert payload to JSON format
};
// Perform the POST request
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText()); // Log response for debugging
}
// Function to retrieve access token
function getAccessToken() {
var tokenUrl = '
https://app.workhub24.com/api/auth/token
';
var clientId = 'YOUR_CLIENT_ID'; // Replace with your Client ID
var clientSecret = 'YOUR_CLIENT_SECRET'; // Replace with your Client Secret
var options = {
method: 'post',
contentType: 'application/x-www-form-urlencoded',
payload: {
'grant_type': 'client_credentials',
'client_id': clientId,
'client_secret': clientSecret
}
};
var response = UrlFetchApp.fetch(tokenUrl, options);
var json = JSON.parse(response.getContentText());
return json.access_token; // Return the access token
}
  1. Update API Credentials & Field Mapping

    Before running the script, update the following parameters:

    1. API Endpoint URL: Replace ‘https://app.workhub24.com/api/datatables/TENANT_ID/DATASTORE_ID/records’ with the correct WorkHub24 datastore POST API endpoint.
    2. Client Credentials: Replace ‘YOUR_CLIENT_ID’ and ‘YOUR_CLIENT_SECRET’ with your WorkHub24 API Client credentials.
    3. Payload Mapping: Adjust the formData indices (formData[1], formData[2], etc.) to match your Google Form structure and the public field names in the WorkHub24 datastore.
    4. After completing the above steps, save the script.
  2. Set Up the Trigger

    To ensure the script runs automatically on form submission:

    1. In Google Apps Script, click Triggers.

    2. Add a new trigger and set the parameters as shown in the following screenshot.

    3. Authorize the script when prompted, after saving the trigger.

    4. Check under Triggers (⏰) to confirm onFormSubmit is listed.

  3. Test the integration

    1. Click Save project to drive.

    2. Submit a test response via your Google Form.

    3. Open Apps Script > Executions to check logs for errors.

    d. Verify that the response appears in your WorkHub24 datastore.