Home » Deeper in to NetSuite » How to Upload Application/Binary Type Files from NetSuite to External Systems using SuiteScript 2.0

How to Upload Application/Binary Type Files from NetSuite to External Systems using SuiteScript 2.0

As a NetSuite developer, you must have come across situations where you needed to export or upload files from the NetSuite File Cabinet to an external system. For example, in a scenario where a customer wants to export their entire NetSuite CRM data (including message attachments) to an external server. Or for example, in a scenario where the customer wants to store their NetSuite documents on an external file sharing service like Dropbox.

CTA - NetSuite Services Banner

External systems facilitate these types of file transfers by exposing their file upload APIs. These APIs require specific values for the HTTP Request Header fields such as Content-Type, Accept, etc. And these APIs are consumed by NetSuite’s SuiteScript APIs in order to send and receive the file data.

The latest APIs from external systems however require certain content types that are not supported by SuiteScript 1.0, which prevents you exporting those types from NetSuite. One example of such unsupported file types is application/binary files, which are not supported in SuiteScript 1.0. Luckily though, SuitScript 2.0 does support this file type, and you can use it to export application/binary files from NetSuite to any external system or application.

CTA - NetSuite Customization Banner

Here’s how you can do that.

1. Create a Suitelet in SuiteScript 2.0

2. Inside the SuiteScript 1.0 script, send a request to the Suitelet you just created, with the file’s id as a parameter. You can use nlapiRequestURL() to send this request

3. Then in the Suitelet you created, load File Content (as shown below)

var fileContent = file.load(fileId).getContents();

4. Then send the HTTP POST request to the External System API along with the required Content-Type header field value, and the File Content as the body of the request (as shown in the snippet below).

var externalSystemRequestObject = {

url: urlTOExternalSystemFileUploadApiEndpoint,

headers : {

Accept:’application/json’,

Content-Type: ‘application/binary’

}

body: fileContent

}

Var externalSystemResponse = http.post(externalSystemRequestObject);

CTA - NetSuite Integration Connector Banner

5. Next, send the external system’s response back to the caller script (as depicted below).

response.write({

output: JSON.stringify(externalSystemResponse)

}

);

And that’s it. By using this approach, you can overcome the Content-Type limitation in SuiteScript 1.0 while leveraging the latest APIs from external systems.

Note:

You will need to have basic knowledge of SuiteScript 2.0 in order to perform this tutorial.

Have a NetSuite development requirement you would like discuss? Get In Touch.

Get In Touch With Our Experts


    Get In Touch With Our Experts

      I have read and agree to the Privacy Policy of Folio3
      I agree to be contacted by Phone or Email by Folio3

      Get in touch with the

      Award-Winning

      End-to-end NetSuite Servicing Agency

      Tell us how may we assist you!