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
-
Open the Apps Script Editor
-
Open your Google Form.
-
Click on the Responses tab.

-
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.
-
After being redirected to the Google Sheet, click on Extensions > Apps Script.

-
-
Copy and Paste the Script
- Delete any existing code in the script editor.
- 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 tokenfunction 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}-
Update API Credentials & Field Mapping
Before running the script, update the following parameters:
- API Endpoint URL: Replace ‘https://app.workhub24.com/api/datatables/TENANT_ID/DATASTORE_ID/records’ with the correct WorkHub24 datastore POST API endpoint.
- Client Credentials: Replace ‘YOUR_CLIENT_ID’ and ‘YOUR_CLIENT_SECRET’ with your WorkHub24 API Client credentials.
- 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.
- After completing the above steps, save the script.
-
Set Up the Trigger
To ensure the script runs automatically on form submission:
-
In Google Apps Script, click Triggers.

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

-
Authorize the script when prompted, after saving the trigger.
-
Check under Triggers (⏰) to confirm onFormSubmit is listed.

-
-
Test the integration
-
Click Save project to drive.

-
Submit a test response via your Google Form.
-
Open Apps Script > Executions to check logs for errors.


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