user1583537
user1583537

Reputation:

UrlFetchApp.fetch Link Length Limit

I'm having some trouble with the UrlFetchApp class, fetch() method. I've singled out the issue, and it seems to be the fact that the actual link I'm fetching is just too long

When I eliminate some needed data(resulting in ~1900 characters), it send the fetch request fine

The length limit is somewhere between 2040 and 2060 characters, as that is where it stops working and I receive a "Bad request" error. I'm assuming it's 2048, as that seems to have been the industry standard some time ago.

I'm needing to fetch data from a link that's upwards of 3400 characters! Is this just too long? 2048 characters might have been understandable a while back, but in this day in age it's a limit that is going to be met quite often

My question is this: Is there a way around this? I'm assuming Google set the limit, is there some way to request this limit be raised?

Thank you!

Upvotes: 3

Views: 2565

Answers (3)

Max Makhrov
Max Makhrov

Reputation: 18707

I used the POST method with payload data instead, showed here:

The classic code is:

// Make a POST request with form data.
var resumeBlob = Utilities.newBlob('Hire me!', 'text/plain', 'resume.txt');
var formData = {
  'name': 'Bob Smith',
  'email': '[email protected]',
  'resume': resumeBlob
};
// Because payload is a JavaScript object, it is interpreted as
// as form data. (No need to specify contentType; it automatically
// defaults to either 'application/x-www-form-urlencoded'
// or 'multipart/form-data')
var options = {
  'method' : 'post',
  'payload' : formData
};
UrlFetchApp.fetch('https://httpbin.org/post', options);

Upvotes: 1

ADW
ADW

Reputation: 4247

The restriction is on the size (2kB) and not on the length of the url.

On March 30, 2018, Google deprecated the URL Shortener service that was used in the accepted answer.

I wrote a script to use the Firebase Dynamic Links Short Links API service.

The docs are here if you want to cook your own.

Upvotes: 1

Srik
Srik

Reputation: 7957

You can try UrlShortener to shorten the URL and then use UrlFetchApp with the shortened URL

Upvotes: 0

Related Questions