# Data from Google Sheets into SprintHub

{% embed url="<https://www.youtube.com/watch?v=6a43kHMrnXA>" %}

### Example script. Modify according to your reality,

```javascript
function onEdit(e) {
  var sheetName = 'Leads'; 
  var sheet = e.source.getSheetByName(sheetName);
  
  if (!sheet || e.range.getSheet().getName() !== sheetName) {
    return;
  }
  
  // Checks if the edit is on the last row (assumes a new row is added manually)
  var lastRow = sheet.getLastRow();
  if (e.range.getRow() === lastRow) {
    sendRowsToWebhook(sheet, lastRow, lastRow);
  }
}

function sendRowsToWebhook(sheet, startRow, endRow) {
  var url = 'https://sprinthub-api-master.sprinthub.app/api/hook/gxxxxxets?i=temxxxxp&access_token=ziqTxxxxxx0-X_';

  for (var row = startRow; row <= endRow; row++) {
    var rowValues = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getValues()[0];

    // Checks if required fields are filled
    if (rowValues[0] === '' || rowValues[2] === '') {
      Logger.log('Row ' + row + ' contains required empty cells.');
      continue;
    }

    // Preparing data to send in the payload
    var payload = {
      'name': rowValues[0],
      'lastName': rowValues[1],
      'mobile': rowValues[2],
      'email': rowValues[3]
    };

    Logger.log('Payload sent:', payload);

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

    try {
      var response = UrlFetchApp.fetch(url, options);
      Logger.log('Webhook response for row ' + row + ':', response.getContentText());
    } catch (e) {
      Logger.log('Error sending payload for row ' + row + ':', e.message);
    }

    // Wait 1 second before sending the next row
    Utilities.sleep(1000);
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sprinthub.com/en/topics/analyze/integrated-webhooks/integrated-webhooks-tutorial-videos/data-from-google-sheets-into-sprinthub.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
