Search code examples
google-apps-scriptgethttp-status-code-403urlfetch

Unable to use fetchURL() in Google apps scripts


I am trying to call the below URL from Google apps script. In my browser it works fine, but when run from Apps script I get the error 'Access denied'.

var response=UrlFetchApp.fetch(url);//Fails with Access denied exception

URL : Gets stock data in JSON format

'Request failed for http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=AXISBANK&series=EQ returned code 403. Truncated server response: Access Denied

Access Denied

You don't have permission to access "http://www.ns... (use muteHttpExceptions option to examine full response)'

Do i need to do anything extra?


Solution

  • Status 403 indicates that everything went as planned, but the recipient denied the request. Without clarification from the host site, it's hard to say why it's rejecting the request, but it could be anything from the request being denied due to an issue with your code, or they may have a service in place that prevents these kinds of requests from unauthorized IPs.

    They may even have blacklisted Google apps script specifically, due to the nature of the site you're connecting too, and the potential for abuse.