Get Keyword Suggestions into Google Sheets with Grow Keywords API

PHOTO EMBED

Mon May 10 2021 14:52:30 GMT+0000 (UTC)

Saved by @admariner

SEO_RULER_EMAIL = "";
SEO_RULER_API_KEY = "";
MAX_KEYWORDS = '5000';

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Keyword Ideas')
    .addItem('Generate Ideas (columns)', 'seoRulerSuggestColumns')
    .addItem('Generate Ideas (columns, append)', 'seoRulerSuggestColumnsAppend')
    .addItem('Generate Ideas (rows)', 'seoRulerSuggestRows')
    .addItem('Generate Ideas (rows, append)', 'seoRulerSuggestRowsAppend')
    .addToUi();  
}

function seoRulerSuggestRows() {  
  var sheet = SpreadsheetApp.getActiveSheet();
  var seed = sheet.getActiveCell().getValue();

  var response = UrlFetchApp.fetch(`https://growkeywords.com/api/suggest?query=${seed}&max=${MAX_KEYWORDS}&token=${SEO_RULER_API_KEY}&email=${SEO_RULER_EMAIL}`);
  var json = response.getContentText();
  var data = JSON.parse(json);  
  var cell = sheet.getCurrentCell();

  sheet.getRange(cell.getRow()+1, cell.getColumn(), data.suggestions.length, 1).setValues(data.suggestions.map((s) => [s]));
}

function seoRulerSuggestRowsAppend() {  
  var sheet = SpreadsheetApp.getActiveSheet();
  var seed = sheet.getActiveCell().getValue();

  var response = UrlFetchApp.fetch(`https://growkeywords.com/api/suggest?query=${seed}&max=${MAX_KEYWORDS}&token=${SEO_RULER_API_KEY}&email=${SEO_RULER_EMAIL}`);
  var json = response.getContentText();
  var data = JSON.parse(json);  
  var cell = sheet.getCurrentCell();

  sheet.getRange(sheet.getLastRow()+1, cell.getColumn(), data.suggestions.length, 1).setValues(data.suggestions.map((s) => [s]));
}

function seoRulerSuggestColumns() {  
  var sheet = SpreadsheetApp.getActiveSheet();
  var seed = sheet.getActiveCell().getValue();

  var response = UrlFetchApp.fetch(`https://growkeywords.com/api/suggest?query=${seed}&max=${MAX_KEYWORDS}&token=${SEO_RULER_API_KEY}&email=${SEO_RULER_EMAIL}`);
  var json = response.getContentText();
  var data = JSON.parse(json);  
  var cell = sheet.getCurrentCell();

  sheet.getRange(cell.getRow(), cell.getColumn()+1, 1, data.suggestions.length).setValues([data.suggestions]);
}

function seoRulerSuggestColumnsAppend() {  
  var sheet = SpreadsheetApp.getActiveSheet();
  var seed = sheet.getActiveCell().getValue();

  var response = UrlFetchApp.fetch(`https://growkeywords.com/api/suggest?query=${seed}&max=${MAX_KEYWORDS}&token=${SEO_RULER_API_KEY}&email=${SEO_RULER_EMAIL}`);
  var json = response.getContentText();
  var data = JSON.parse(json);  
  var cell = sheet.getCurrentCell();

  sheet.getRange(cell.getRow(), sheet.getLastColumn()+1, 1, data.suggestions.length).setValues([data.suggestions]);
}
content_copyCOPY

https://codingforseo.com/google-sheets-keywords-suggest