This guide will walk you through the process of uploading files to Netsuite using Node.js.
We will provide step-by-step instructions and example code to help you successfully upload files to Netsuite's File Cabinet.
Step 1: Install Required npm Modules
To begin, make sure you have Node.js installed on your system. Then, install the necessary npm modules by running the following command in your project directory:
npm install nsupload
Step 2: Configuration
Next, open your script file and import the `nsupload` module. Configure the module by providing your email, password, Netsuite account number, and script number.
Set the method to `PUT` as specified in the instructions.
var sendToNetsuite = require('nsupload').config({
email: 'your_email@example.com',
password: 'your_password',
account: 'your_account_number',
script: 'your_script_number',
method: 'PUT'
});
Step 3: File Upload
Now, you are ready to upload a file to Netsuite. Use the `sendToNetsuite` function and provide the file path as the first argument.
You can also handle any errors or receive the response body in the callback function.
sendToNetsuite('./path/to/your/file', function(err, body) {
if (err) {
console.error(err);
} else {
console.log('Success!');
console.log(body);
}
});
Step 4: Testing
Save the file and run your script using Node.js. If everything is correctly configured, you should see the success message and the response body in the console.
Additional Solution:
If you are facing issues with the `nsupload` module, you can try using an alternative module called `nscabinet`. Follow the steps below to upload files using the `nscabinet` module:
Step 1: Installation
Install the `nscabinet` and `gulp` (or `vinyl-fs`) npm modules by running the following command:
npm install nscabinet gulp
Step 2: Prepare the Code
Import the `nscabinet` module and `gulp` (or `vinyl-fs`) in your script file.
Specify your email, password, Netsuite account number, and other required parameters. Then, define the file(s) you want to upload.
var nscabinet = require('nscabinet');
var gulp = require('gulp'); //or just vinyl-fs
gulp.src('path/to/your/file.js')
.pipe(nscabinet({
email: 'your_email@example.com',
password: 'your_password',
account: 'your_account_number',
rootPath: '/SuiteScripts',
script: 'myuploadfile',
deployment: 2
}))
Step 3: Run the Code
Save your file and execute the script using Node.js. This should initiate the file upload process to Netsuite's File Cabinet.
Troubleshooting:
If you encounter the error message "SSS_INVALID_SCRIPTLET_ID - That Suitelet is invalid, disabled, or no longer exists," ensure that you have uploaded the required Restlet to Netsuite.
If the issue persists, we recommend investigating the specific error further or reaching out to Netsuite support for assistance.
Congratulations! You have learned how to upload files to Netsuite using Node.js.
By following the provided instructions and examples, you can now enhance your capabilities in working with Netsuite's File Cabinet.
Start uploading and managing your files efficiently using the power of Node.js.