Example Hello World RESTlet

Using RESTlets can be more complicated than using other script types. Other script types are deployed and then can execute when needed, however, RESTlets are deployed and then must be called to be executed. To call a RESTlet successfully, you must do these three things:

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 by using the http get method. Because the RESTlet takes no arguments, you would not need to extend the URL with additional values. For testing purposes, you could use the value that appears in the External URL field of the script deployment record. (However, in an integration, remember that you must dynamically discover 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 

        

After you add the two required headers, the generated call would look like the following:

          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 would return the following response:

          Hello World! 

        

For information about troubleshooting any errors that may occur in your RESTlet, 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

General Notices