# Dados do Google Sheets para dentro do SprintHub

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

### Script de Exemplo. Altere conforme sua realidade,

```javascript
function onEdit(e) {
  var sheetName = 'Leads'; 
  var sheet = e.source.getSheetByName(sheetName);
  
  if (!sheet || e.range.getSheet().getName() !== sheetName) {
    return;
  }
  
  // Verifica se a edição é na última linha (supõe que uma nova linha seja adicionada manualmente)
  var lastRow = sheet.getLastRow();
  if (e.range.getRow() === lastRow) {
    enviarLinhasParaWebhook(sheet, lastRow, lastRow);
  }
}

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

    // Verifica se os campos obrigatórios estão preenchidos
    if (linha[0] === '' || linha[2] === '') {
      Logger.log('A linha ' + row + ' contém células vazias obrigatórias.');
      continue;
    }

    // Preparando os dados para enviar no payload
    var payload = {
      'nome': linha[0],
      'sobrenome': linha[1],
      'celular': linha[2],
      'email': linha[3]
    };

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

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

    try {
      var response = UrlFetchApp.fetch(url, options);
      Logger.log('Resposta do webhook para a linha ' + row + ':', response.getContentText());
    } catch (e) {
      Logger.log('Erro ao enviar o payload para a linha ' + row + ':', e.message);
    }

    // Aguardar 1 segundo antes de enviar a próxima linha
    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/topicos/analisar/webhooks-integrados/webhooks-integrados-videos-tutoriais/dados-do-google-sheets-para-dentro-do-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.
