# Integrated Webhooks - How to connect a Google Sheets spreadsheet to Sprinthub

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2Fud8oJmFpgO2lyVzk9lDq%2Fundraw_Augmented_reality_re_f0qd.png?alt=media&#x26;token=56cb05b5-12ee-451a-a9a5-1d4f6b623cf6" alt=""><figcaption></figcaption></figure>

### Steps **to Connect a Google Sheets Spreadsheet to Sprinthub via Webhooks to send data to sprinthub**

Here are the basic steps to set up this integration:

#### Pre**paration of the Google Sheets Spreadsheet:**

* Make sure the spreadsheet contains the data needed to feed Sprinthub, such as lead details like Name, Lastname, email and whatsapp.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FooCW55uqFzzJM6gwkSB7%2Fimage.png?alt=media&#x26;token=2dbd8a0e-4914-4ef6-aa4c-0de674f93e14" alt=""><figcaption></figcaption></figure>

#### C**onfiguration of the Webhook in Sprinthub:**

* Access Sprinthub and go to the Webhook settings; for the integration we should leave it as follows:

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FpAN7qAJPjteNS3MjfiFW%2Fimage.png?alt=media&#x26;token=fe14a4c2-f95f-4cda-9a01-a8c233b31de2" alt=""><figcaption></figcaption></figure>

* First it is necessary to create the keyword to connect the webhook, for example:

```javascript
 'https://sprinthub-api-master.sprinthub.app/api/hook/google-sheets?i=g4&access_token=tdtcX1Hrw5MmTzQiLVA8_AtMA6H-FYA-uM_gnoYPVLS25A4VNT'
```

* Request body: What you want to receive from your spreadsheet, in our case Name, lastname, email and whatsapp.

{% hint style="info" %}
Remember to put identifiers so that there is no duplication of leads.
{% endhint %}

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FECpwEL1fM3RjwIIekdI1%2Fimage.png?alt=media&#x26;token=903a0b50-9374-44a4-a083-4814b56637b7" alt=""><figcaption></figcaption></figure>

* Automatic lead creation enabled with the tokens to perform the creation.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2F6GaajSDV18GZRyigXUkO%2Fimage.png?alt=media&#x26;token=3d746f8e-f799-4f24-98c3-9f3885e0b159" alt=""><figcaption></figcaption></figure>

#### Configura**tion of the Google Sheets Spreadsheet:**

* Open the spreadsheet and navigate to "Extensions" > "Apps Script". A screen will open where you can put your script for how the data will be sent to the webhook.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FMYqIq010FkheEf7119p4%2Fimage.png?alt=media&#x26;token=dcd403d5-aca2-4491-90d0-373357cc766f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FpjVfXM55f4gjo7WH8ufq%2Fimage.png?alt=media&#x26;token=89184607-5e69-47d0-adcb-8b050a2de75a" alt=""><figcaption></figcaption></figure>

* In the Script Editor, write a function that will be triggered whenever a new row is added to the spreadsheet. This function can be configured to send a POST to the Sprinthub webhook URL, with the project's relevant data.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FfhhAi53Pdt5RE7PnvMxm%2Fimage.png?alt=media&#x26;token=db005a38-43d5-43f6-b984-b244d9b77507" alt=""><figcaption></figcaption></figure>

Below is the example code:

<pre class="language-javascript"><code class="lang-javascript"><strong>function enviarDadosParaWebhook() {
</strong>  var url = 'https://sprinthub-api-master.sprinthub.app/api/hook/google-sheets?i=g4&#x26;access_token=tdtcX1Hrw5MmTzQiLVA8_AtMA6H-FYA-uM_gnoYPVLS25A4VNT';

  var planilha = SpreadsheetApp.getActiveSpreadsheet();
  var abaAtiva = planilha.getSheetByName('Leads '); 

  if (!abaAtiva) {
    Logger.log('The specified sheet was not found.');
    return;
  }

  var dados = abaAtiva.getDataRange().getValues();

  // Remove the header row
  dados.shift(); // Remove the header

  // Filter empty or incomplete rows
  dados = dados.filter(function(row) {
    // Check if all fields are filled (assuming name, lastname, email and whatsapp are in the first four columns)
    return row[0] !== '' &#x26;&#x26; row[1] !== '' &#x26;&#x26; row[2] !== '' &#x26;&#x26; row[3] !== '';
  });

  // Logging for debugging
  Logger.log('Filtered data:', dados);

  // Preparing data to send in the payload
  var payload = {
    'dados': dados.map(function(row) {
      return {
        'name': row[0],
        'lastname': row[1],
        'email': row[2],
        'whatsapp': row[3]
      };
    })
  };

  // Logging for debugging
  Logger.log('Payload sent:', payload);

  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'payload' : JSON.stringify(payload),
    'muteHttpExceptions': true  
  };
  }
</code></pre>

#### Test and Debugging

* After testing and debugging the integration, and verifying that everything is correct. Run and check if the call was made in sprinthub.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2Fy6pjhQcXIdR8oziEWKMp%2Fimage.png?alt=media&#x26;token=0075877d-b59d-439c-9677-b502b988b7de" alt=""><figcaption></figcaption></figure>

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FL4XIzTgnNv9kkC8wXaYZ%2Fimage.png?alt=media&#x26;token=9a90e98e-a4ad-442c-a1b8-eb3dd4f2b0f5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FEpRVAq9TRStDGAHRilAo%2Fimage.png?alt=media&#x26;token=2ec59aa7-9a20-4072-9101-4d9b5a94eeb7" alt=""><figcaption></figcaption></figure>

* With the webhook successfully connected, we can add triggers, where editing the spreadsheet will be sent to the webhook files:

{% hint style="warning" %}
Disable automatic saving; with it enabled any row made will be POSTed to the webhook.
{% endhint %}

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FbYmqBvPUgZPYs9HmnBvq%2Fimage.png?alt=media&#x26;token=c011b12b-28d1-4ae6-9f14-d9ebf5742481" alt=""><figcaption></figcaption></figure>

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2FOAZ5NJH3qbGn7QkRFDCR%2Fimage.png?alt=media&#x26;token=336c18ca-9da2-4599-bfb4-b6a7aa4762ee" alt=""><figcaption></figcaption></figure>

* Be aware of adjustments or improvements that may be necessary based on practical use.

<figure><img src="https://684109703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9FzUKkagBNy5uQ7AtGNa%2Fuploads%2Fh9AT3p1BezS2tnqwUVJB%2Fimage.png?alt=media&#x26;token=3cf283a0-9cff-413f-ad8a-13b692f94ba4" alt=""><figcaption></figcaption></figure>

**Conclusion**

Integrating a Google Sheets spreadsheet with Sprinthub via webhooks not only simplifies the workflow but also improves accuracy and efficiency in project management. With proper automation, you can transform how your teams collaborate and perform tasks, making the most of the capabilities of these powerful productivity and management tools.
