Go to https://docs.google.com/forms and create a form
Add the fields you need ;)
Go to https://app.cadulis.com
Navigate to Settings
> External Access
> Create External Access
Select the “Webservice REST” type
In the Rest API section, have you learned how to create your webservice access?
Check the box to allow Create an activity
and, if needed, Create a client
Save.
Copy your API key
available in the corresponding section
Now we want to inject Google Form responses directly into Cadulis. We’ll automate this using the script editor
.
From your Google Form, click on and choose Script Editor
Add a file and use the following code, making sure to replace API key
with the one obtained above
Below, remember to replace apiKey and activityTypeId at the beginning of the script
:
function onFormSubmit(e) {
// apiKey: Replace with the key of the external access of your Cadulis configuration
var apiKey = 'XXXXXXXX';
// activityTypeId: Replace with the id of activity type (in catalog) you want to create an activity
var activityTypeId = 1234;
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var responseId = latestResponse.getId();
var response = latestResponse.getItemResponses();
var responseMap = {};
// Generate a string containing all questions by title and their answer
var responseString = '# ' + responseId + "\n\n";
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle();
var answer = response[i].getResponse();
responseString += question + ' : ' + answer + "\n";
responseMap[question] = answer;
}
// generate a unique reference from Google Form response ID
var cref = responseId.substring(0, 15) + '-' + responseId.substring(responseId.length - 15);
// prepare Cadulis data
var formData = {
'cref': cref,
'reference': cref,
'intervention_type':{
'id': activityTypeId
},
'comment': responseString,
'title': 'Réponse sur Google Form'
};
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(formData)
};
console.log(formData);
var url = 'https://api.cadulis.com/connectors/' + apiKey + '/interventions';
var result = UrlFetchApp.fetch(url, options);
console.log(result.getContentText());
}
To have this script run on each form submission, go to the left menu and select Triggers
In “Event type”, choose On form submit
, and save.
That’s it: each time a response is submitted on Google Form, an activity will be created in Cadulis!