0

I am working on a simple Google AppScript, where the public API works on postman, however it gives an error Unauthorized when I call it from Script. Can someone please help. Below is the code

I tried with and without Headers. With Headers it gives an error "Attribute provided with invalid value: Header:Host"

var url = 'https://www.moneycontrol.com/mc/widget/mfnavonetimeinvestment/get_chart_value?isin=INF846K01E25&dur=1W';

 var headers = {
    "Host": "www.moneycontrol.com",
    "Content-Type": "application/json",
    "Accept": "application/json"
  };
 
  var options = {
    "method": "GET",
    "contentType": "application/json",
    "headers": headers,
  };


  try {
    const response = UrlFetchApp.fetch(url, options);
    const data = JSON.parse(response.getContentText());
    Logger.log(data);
  } 
  catch (f) {
    Logger.log(f.message);
  }
2
  • 1
    You should review the requirements/restricions of the API, in this case, www.moneycontrol.com. One source might be the website's robots.txt file. They might be blocking Google "robots". They might also use other parameters / attributes that is blocking UrlFetchApp. Unfortunately there are some of them that can't be customized.
    – Wicket
    Commented Oct 11, 2024 at 16:17
  • where the public API works Would you please provide a reference for documentation for the Moneycontrol.com "Public" API.
    – Tedinoz
    Commented Oct 14, 2024 at 2:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.