π What is a RESTlet?
A RESTlet is a custom REST API built inside NetSuite using SuiteScript.
Unlike SuiteTalk (which has fixed endpoints), RESTlets allow you to:
- Build custom business logic.
- Decide what input and output look like.
- Control performance and governance.
π Think of RESTlets as your own API endpoints inside NetSuite.
π Why Use RESTlets?
- Flexibility β You decide how data is processed.
- Custom Logic β Validate or transform data before saving.
- Lightweight β Easier than SOAP, tailored for your exact needs.
- Integration-Friendly β External apps can call your RESTlet with JSON.
βοΈ Step 1: Create a Basic RESTlet Script
Example: A RESTlet that returns customer details.
/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
define(['N/record'], (record) => {
/**
* GET function β retrieve customer by ID
*/
const get = (requestParams) => {
try {
let customer = record.load({
type: record.Type.CUSTOMER,
id: requestParams.id
});
return {
id: customer.id,
companyName: customer.getValue('companyname'),
email: customer.getValue('email'),
phone: customer.getValue('phone')
};
} catch (e) {
return { error: e.message };
}
};
return { get };
});
βοΈ Step 2: Deploy the RESTlet
- In NetSuite, go to Customization β Scripting β Scripts β New.
- Upload your script file.
- Define the Script Record and Deployments.
- Note down the RESTlet URL β this will be your API endpoint.
Example:
https://<account_id>.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1
βοΈ Step 3: Call RESTlet from Postman
- Open Postman.
- Create a GET request with your RESTlet URL.
- Add Authorization headers (Token-Based Auth is recommended).
Example Request:
GET https://123456.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1&id=456
Authorization: NLAuth nlauth_account=123456, nlauth_consumer_key=XXXX, nlauth_token=YYYY
Example Response:
{
"id": "456",
"companyName": "ABC Corp",
"email": "info@abccorp.com",
"phone": "123-456-7890"
}
π§βπ» Extending Your RESTlet
You can add more HTTP methods to your RESTlet:
get()
β retrieve datapost()
β create recordsput()
β update recordsdelete()
β remove records
Example: Create a new customer with post()
const post = (data) => {
try {
let customer = record.create({ type: record.Type.CUSTOMER });
customer.setValue({ fieldId: 'companyname', value: data.companyName });
customer.setValue({ fieldId: 'email', value: data.email });
let id = customer.save();
return { success: true, id: id };
} catch (e) {
return { error: e.message };
}
};
β Summary
- RESTlets = Custom APIs in NetSuite.
- They allow flexible, custom logic beyond SuiteTalk.
- Can handle GET, POST, PUT, DELETE requests.
- Best way to integrate with external apps when standard APIs donβt fit.
This tutorial showed you how to create, deploy, and test a RESTlet.
Leave a Reply