Apps Script - Ungzipping a .gz results in unexpected output

66 views
Skip to first unread message

Judah Hooper

unread,
Jan 25, 2024, 5:48:20 AM1/25/24
to Google Apps Script Community
0

'I'm working with the slack analytics api, specifically the admin.analytics.getFile method. I'm running into a strange error when dealing with the response from my call.

Here's the relevant portion of my script for reference;

function getData() { var analyticsUrl = `https://slack.com/api/admin.analytics.getFile?type=member&date=2023-12-30`; var analyticsOptions = { 'method': 'GET', 'headers' :{ 'accept-encoding': 'gzip', 'Authorization': 'Bearer REDACTED' } }; var response = UrlFetchApp.fetch(analyticsUrl, analyticsOptions); Logger.log(response.getAllHeaders()); var placeholderBlob = response.getBlob().setContentType('application/x-gzip'); Logger.log(placeholderBlob); Logger.log(Utilities.ungzip(placeholderBlob)); Logger.log(placeholderBlob.getDataAsString()) };

The GET returns a .json.gz file, which I had expected to convert to a blob, and then ungzip using the built in method. Here's the execution logs in order:

  • {Access-Control-Allow-Headers=slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, x-b3-sampled, x-b3-flags, x-backend=main_normal main_canary_with_overflow main_control_with_overflow, Access-Control-Expose-Headers=x-slack-req-id, retry-after, Vary=Accept-Encoding, x-accepted-oauth-scopes=admin.analytics:read, Referrer-Policy=no-referrer, x-slack-unique-id=ZbEuKziT4Vd-8mjR7E7KJQAAAAo, x-server=slack-www-hhvm-main-iad-wlqz, Pragma=private, x-oauth-scopes=identify,admin.analytics:read, Expires=Sat, 26 Jul 1997 05:00:00 GMT, Content-Length=10961, x-slack-shared-secret-outcome=no-match, Via=1.1 slack-prod.tinyspeck.com, envoy-www-iad-evdldebd, envoy-edge-pdx-morbazdg, Date=Wed, 24 Jan 2024 15:35:07 GMT, Cache-Control=private, Strict-Transport-Security=max-age=31536000; includeSubDomains; preload, x-edge-backend=envoy-www, Content-Type=application/gzip, x-envoy-attempt-count=1, x-slack-edge-shared-secret-outcome=no-match, x-envoy-upstream-service-time=265, Content-Disposition=attachment; filename="NAMEREDACTED.json.gz"; filename*=utf-8''NAMEREDACTED%202023-12-30.json.gz, Server=Apache, Access-Control-Allow-Origin=*, x-slack-backend=r}
  • Blob
  • Blob
  • Logging output too large. Truncating output. (Followed by a load of raw data)

This appears to me that the content-type is correct for passing into ungzip. Why then do I get raw data when the final logger hits the console?

Let me know if I can provide any further context or clarification.


http://capuk.org    https://www.facebook.com/CAPuk/    https://twitter.com/CAPuk    https://www.instagram.com/capuk_org    https://uk.linkedin.com/company/capuk    https://www.youtube.com/c/ChristiansAgainstPoverty    https://www.tiktok.com/@christiansagainstpoverty

Christians Against Poverty
Registered Office: Jubilee House, 1 Filey Street, Bradford, BD1 5LQ
t: 01274 760720

Registered Charity No: 1097217. Charity registered in Scotland No: SC038776
Company Limited by Guarantee, Registered in England and Wales No. 4655175
Christians Against Poverty is authorised and regulated by the Financial Conduct Authority.

The information contained in this email is confidential and may be subject to legal privilege. Access to this email by anyone other than the intended recipient is unauthorised. If you are not the intended recipient, please do not copy, distribute or disclose the email or any part of its contents or take any action in reliance on it. If you have received this email in error, please notify us immediately by email or telephone. All reasonable precautions have been taken to ensure no viruses are present in this email. As Christians Against Poverty cannot accept responsibility for loss or damage arising from the use of this email or attachments we recommend that you subject these to your virus checking procedures prior to use.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages