Hello fellow GAS devs,
I'm using the UrlFetchApp to call this neat GrammarBot API. The API itself accepts strings that are up to 50,000 characters in length, but it seems that the UrlFetchApp method greatly limits the possibilities of using this API.
When using GrammarBot, I'm able to successfully make a call with the following code:
function grammarBotTest () {
var rawText = 'This is a free online calculator which counts the number of characters or letters in a text, useful for your tweets on Twitter, as well as a multitude of other applications.';
var encodedText = encodeURI(rawText);
var url = 'http://api.grammarbot.io/v2/check?api_key=AF5B9M2X&text=' + encodedText + '&language=en-US';
// var url = 'http://api.grammarbot.io/v2/check?api_key=AF5B9M2X&text=I%20can%27t%20remember%20how%20to%20go%20their.&language=en-US';
var params = {
'contentType': 'application/json',
'method': 'get',
'headers': {
'api-key': '###'
},
'muteHttpExceptions': true
}
var response = UrlFetchApp.fetch(url, params);
Logger.log(response); // Logger.log() replaces console.log() in Google Apps Script
}
The problem is that, when the rawText variable at the top of the function is a text string of a more useful size (for example, we are trying to help students with their resumes, and this involves around 7000 characters usually), the UrlFetch method will reject the url provided as an argument to the method because the URL itself is too long. After reviewing a few threads on Stack Overflow, I see that the UrlFetchApp will reject URLs as arguments that are ~2000 characters or more.
If you can help me troubleshoot this problem or propose an alternative method of calling this API, I'd be grateful!