Example Hello World RESTlet
RESTlets can be a bit trickier than other script types. Other script types run when needed after deployment. With RESTlets, you deploy them but have to call them for them to run. To call a RESTlet, make sure you do these three things:
-
Correctly identify your NetSuite accoun'ts RESTlet domain
-
Use an HTTP method that matches an entry point in your script
-
Use two required headers: Content-Type and Authorization.
For details on the required headers, see Creating a Content–Type Header and RESTlet Authentication.
The following example RESTlet is a simple implementation of the standard Hello World example implemented using the RESTlet get entry point.
RESTlet
/**
* @NApiVersion 2.x
* @NScriptType Restlet
*/
define([], function() {
return {
get : function() {
return "Hello World!"
}
}
});
Example Get Call and Response
You call this RESTlet with the http get method. Since it doesn’t take any arguments, you don’t need to add anything else to the URL.For testing, just use the value in the External URL field of the deployment record. But for integrations, make sure you dynamically find the RESTlet domain. See Dynamically Generating a Full URL).
For example, you could call this RESTlet by using a URL like the following — one that does not include embedded parameters:
https://<accountID>.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=482&deploy=1
Once you add the two required headers, your call will look like this:
GET /app/site/hosting/restlet.nl?script=482&deploy=1 HTTP/1.1
HOST: <accountID>.restlets.api.netsuite.com
authorization: NLAuth nlauth_account=12345, nlauth_email=john@smith.com, nlauth_signature=Welcome123
content-type: application/json
cookie: ...
The RESTlet returns this response:
Hello World!
For help troubleshooting RESTlet errors, see SuiteScript 2.x RESTlet Error Handling and Entry Point Script Validation Error Reference.
Related Topics
- SuiteScript 2.x RESTlet Script and Request Examples
- Example of a RESTlet that Retrieves, Deletes, Creates, and Upserts a NetSuite Record
- Example of a RESTlet that Adds Multiple Records
- Example of a RESTlet that Manipulates Scheduled Script
- Example of a Client Script that Calls a RESTlet
- Example of a Suitelet that Calls a RESTlet
- Example of a Shell Script that Calls a RESTlet