2

I'm doing a URL call in a API but I've got this error

TypeError: Cannot find function getContentText in object

Here is bellow my code. I even tried to encode the URL but still not working. Could you please tell me where I'm wrong ? And what is the fix ?

Thank you,

  var url = 'https://welcome.de.coremetrics.com/analyticswebapp/api/1.0/report-data/explore/explore.ftlid=634022';  
  var params = {
    'clientId': 'mi_id',
    'format': 'JSON',
    'userAuthKey' : 'my_key',
    'language' : 'en_US',
    'viewID' : 'default.ftl',
    'period_a' : 'D20170601',
    'fileName' : 'explore_explore^id=634022_default_view_D20170601.json'
  }
   var options = {
   'method' : 'GET',
   'payload' : params
 };
 
   response = UrlFetchApp.getRequest(url,options);
  var data = JSON.parse(response.getContentText());

3
  • At UrlFetchApp.getRequest(), there is no getContentText(). You can directly see response. So you can use Logger.log(response). If you want to do fetch, please change UrlFetchApp.getRequest() to UrlFetchApp.fetch(). In the case of UrlFetchApp.fetch(), getContentText() can be used for the response. The detail information is developers.google.com/apps-script/reference/url-fetch/… Commented Jul 12, 2017 at 8:55
  • Thank you for this ! It works ! Commented Jul 12, 2017 at 12:22
  • Welcome. Thank you, too. Commented Jul 12, 2017 at 21:50

1 Answer 1

1

Solution found:

  res = encodeURI(query)
  response = UrlFetchApp.fetch(res, {muteHttpExceptions: true, escaping: false}).getContentText();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.