> For the complete documentation index, see [llms.txt](https://docs.sprinthub.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sprinthub.com/en/topics/analyze/integrated-webhooks/integrated-webhooks-tutorial-videos/data-from-google-sheets-into-sprinthub.md).

# Data from Google Sheets into SprintHub

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

### Sample Script. Adjust according to your needs,

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

function sendLinesToWebhook(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 line = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getValues()[0];

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

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

    Logger.log('Sent payload:', 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 the payload for row ' + row + ':', e.message);
    }

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