Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseApiResponse not working correctly #1

Open
jimtomas opened this issue Feb 15, 2018 · 1 comment
Open

parseApiResponse not working correctly #1

jimtomas opened this issue Feb 15, 2018 · 1 comment

Comments

@jimtomas
Copy link

If the header is set to false for KEYWORD_VOLUME_SEMRUSH and the return is "ERROR 50" then the function returns "#REF!". Appears there needs to be a check for ERROR 50, then ignore the header setting.

@dsottimano
Copy link
Owner

Thanks for catching that, will add the fix into the newer version of the script. For now, please change your KEYWORD_VOLUME_SEMRUSH function code to the following:

/**

  • Returns Keyword Volume from semrush
  • @param {"apartments"} query REQUIRED The keyword you want information for. Example: "brown shoes".
  • @param {true} excludeHeaders OPTIONAL true to EXCLUDE column headers or false to include. Default is false.
  • @param {"us"} db OPTIONAL The country database you want to search from, default is "us"
  • @return Returns search volume, cpc, etc..
  • @customfunction
    */
function KEYWORD_VOLUME_SEMRUSH(query,excludeHeaders,db) {
  if (!query) return "Error: Missing query"
  var db = db || SemrushGlobal.data.DEFAULT_DB
  SemrushGlobal.methods.giveApiRest()
  
  if (!checkAccount()) return SemrushGlobal.data.ERROR_MESSAGE 
  
  try {
    var result = UrlFetchApp.fetch(SemrushGlobal.queries.keywordVolume + SemrushGlobal.data.API_KEY+"&export_columns=Ph,Nq,Cp,Co,Nr&phrase="+query+"&database="+db).getContentText()
    if (result.indexOf("ERROR") > -1) throw "ERROR 50 :: NOTHING FOUND"
    return parseApiResponse(result,excludeHeaders)
  } catch (e) {
    return e
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants