A RESTlet is a server-side SuiteScript that exposes a custom REST-based web service in NetSuite. Unlike standard REST endpoints, RESTlets give you full control over the logic, authentication, and data returned β making them the most flexible integration option in NetSuite.
In this tutorial, you’ll learn exactly how to create, deploy, and test a RESTlet from scratch using SuiteScript 2.1.
What Is a RESTlet?
A RESTlet is a SuiteScript script type that maps to HTTP methods:
- GET β retrieve data
- POST β create records
- PUT β update records
- DELETE β remove records
RESTlets are deployed as Script Deployments and accessible via a unique URL that external systems can call.
Prerequisites
Before creating a RESTlet, make sure you have:
- A NetSuite account with SuiteScript permissions
- Developer role or Administrator access
- Basic knowledge of SuiteScript 2.1
Step 1: Write the RESTlet Script
Create a new file called restlet_example.js with the following code:
/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
define(['N/record', 'N/log'], function(record, log) {
// GET β retrieve a customer by internal ID
function doGet(params) {
log.debug('GET called', params);
var customerId = params.id;
var customerRecord = record.load({
type: record.Type.CUSTOMER,
id: customerId
});
return {
id: customerId,
name: customerRecord.getValue('companyname'),
email: customerRecord.getValue('email')
};
}
// POST β create a new customer
function doPost(body) {
log.debug('POST called', body);
var newCustomer = record.create({ type: record.Type.CUSTOMER });
newCustomer.setValue('companyname', body.name);
newCustomer.setValue('email', body.email);
var newId = newCustomer.save();
return { success: true, id: newId };
}
// PUT β update an existing customer
function doPut(body) {
log.debug('PUT called', body);
var customerRecord = record.load({
type: record.Type.CUSTOMER,
id: body.id
});
customerRecord.setValue('companyname', body.name);
customerRecord.save();
return { success: true, id: body.id };
}
return { get: doGet, post: doPost, put: doPut };
});
Step 2: Upload the Script to NetSuite
- Go to Documents > Files > SuiteScripts in NetSuite.
- Upload your
restlet_example.jsfile.
Step 3: Create a Script Record
- Go to Customization > Scripting > Scripts > New.
- Set the Script Type to RESTlet.
- Select your uploaded script file.
- Map the functions:
GET FunctionβdoGet,POST FunctionβdoPost,PUT FunctionβdoPut. - Click Save.
Step 4: Deploy the Script
- On the Script record, go to the Deployments tab.
- Click New Deployment.
- Set the Status to Released.
- Under Audience, set the roles that can access this RESTlet.
- Click Save. Copy the External URL β this is your RESTlet endpoint.
Step 5: Test the RESTlet
Use Postman (or any REST client) to test your RESTlet:
- Method: GET
- URL: Your External URL from the deployment
- Auth: Token-Based Authentication (TBA) or OAuth 2.0
- Params:
id=1(a valid customer internal ID)
A successful response will return a JSON object with the customer data.
Next Steps
Now that your RESTlet is live, you can:
- Connect to it from external systems β see Calling a NetSuite RESTlet from External Systems.
- Secure it with Token-Based Authentication β see Token-Based Authentication (TBA) in NetSuite.
- Use OAuth 2.0 for modern auth flows β see OAuth 2.0 in NetSuite.