Netsuite Suitescript Decode Base64

I’m doing Api integration with Suitescript 2.0. A data encoded with base64 is returned from the Api. Here I need to reach the data I want by decoding the base64 and saving the xml data returned as a .zip and unzip it.

The relevant data can be run in Notepad++ with Plugins > MIME Tools > Decode Base64, saved as zip and opened with unzip.

The script I’m working with is a shcedule script.

I tried the two methods mentioned to decode in Suite Answers.

1- From base64 to UTF_8 with N/encode module (Returned result is completely wrong for this problem)

2 – The solution in the link: https://netsuite.custhelp.com/app/answers/detail/a_id/41271/kw/base64%20decode

(In this solution, when you save the returned data as zip, it gives an “Unexpected end of the archive” error when opening the zip.)

 

Rookie Asked on December 20, 2021 in SuiteScript.
Add Comment
1 Answer(s)

First thing to know is that suitescript api’s represent binary data as base64, so your data is probably more useful in base64 form. For example, you can use N/file to create a zip file in NetSuite’s file cabinet while keeping the contents bas64 encoded.

Second thing is that using N/encode or that suiteanswer artile is a mistake, it converts the base64 encoded string into an actual plain text string. Thats wrong, your data isnt plain text. At best, you want a library that implements atob or btoa, which are functions designed to work with binary data.

Third is that suitescript by itself will not get you to unzipping the zip file. The only compression related module is N/compress, which doesn’t actually support unzipping. Theoretically you can find compression libraries on npm that you can get working suitescript, but the performance is bad and you risk hitting execution count limits. I simply recommend doing your integration on your own server and integrate the results of that with NetSuite instead.

Advanced Answered on December 21, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor