2

I am using google app script to Call UPS api and generate shipping label. However the API response is truncated and i am unable to decode base64 encoded image which is part of the JSON response object as it is truncated.

I am also not getting any truncation error messages or responses from the UPS servers, neither is google apps script throwing an error

Have contacted UPS support with the JSON request and it seems to works fine at their end.

// Here is the code for API call.

function getLabel() {
  var userName =  "myUPS_username";
  var password = "*********";
  var accessKey = "my_access_key";
  var transId = "Trans123";
  var transactionSrc = "upstest";
  var url = "https://wwwcie.ups.com/ship/v1807/shipments";

  var header =   {
    'AccessLicenseNumber' : accessKey,
    'password' : password,
    'transId' : transId,
    'transactionsrc' : transactionSrc,
    'username' : userName
  };

  // parameters for url fetch
  var params =   {
    'method': 'GET',
    'contentType': 'application/json',
    'headers': header,
    'payload' : JSON.stringify(payload)
  };

  // call the UPS Shipment API
  var response = UrlFetchApp.fetch(url, params);
}

Not including the JSON payload here

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
  • 1
    I think that providing a sample returned values from API will help users think of the issue and solution. Of course, please remove your personal information. – Tanaike Oct 15 '19 at 22:11
  • How big is the return? Urlfetch has 50mb limit so its possible the image will be truncated for that reason. I don't believe gas throws an error if this is hit though –  Oct 17 '19 at 15:08

1 Answers1

0

Answer:

UrlFetchApp() has functionality and response limitations, including POST and response sizes.

More Information:

As per the Apps Script Documentation, URL Fetch has Limitations which are implemented in the methods themselves. The limitations are as follows:

  • URL Fetch response size: 50MB/call
  • URL Fetch headers: 100/call
  • URL Fetch header size: 8kB/call
  • URL Fetch POST size: 50MB/call
  • URL Fetch URL length: 2kB/call

Unfortunately, there is no way to get around this.

Feature Request:

There is a Feature Request on Google's Issue Tracker requesting the increase of the UrlFetch response size limit already. This Feature Request can be found here, which you can give a star (☆) in the top left to let Google know more people wish for this request. There is already a response from them saying 'We'll consider raising the quota if there is enough interest from the developer community.', so letting them know this is a wanted feature is a good way to go.

References:

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54