Selecting an HTTP/HTTPS Method for Calling a RESTlet

When you call a RESTlet, you can use one of four supported http/https methods: delete, get, post, or put. And, as of NetSuite 2020.2, you can use the N/https module to communicate between SuiteScript scripts, RESTlets, and SuiteTalk REST endpoints without having to reauthenticate by using the https.requestRestlet(options) and https.requestSuiteTalkRest(options)) methods to send HTTPS requests to a RESTlet or SuiteTalk REST endpoints.

When calling a RESTlet, there are a few things to keep in mind:

A Call’s Method Must Match an Entry Point

For each supported http/https method (delete, get, post, put), there is a corresponding RESTlet entry point. For a call to be successful, the method used in the call must match an entry point defined in the RESTlet’s interface.

The following example shows a successful pairing of a RESTlet and a call to that RESTlet. In this example, a Suitelet calls the RESTlet by using the https.get method. Because the example RESTlet’s interface includes a get entry point the call would be successful.

An example call to match the entry point of a Suitelet. The call's method must match then entry point.

HTTP/HTTPS Methods are Dependent on RESTlet Script Entry Points

The implementation of the RESTlet may not strictly adhere to the expected functionality of the http/https method used to call the RESTlet or the corresponding RESTlet entry point. For instance, a RESTlet could define its get entry point to accept data to post.

The following http methods are supported for RESTlets: delete, get, post, and put. These methods are defined at the following link: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html.

However, be aware that the way a RESTlet behaves is defined in the RESTlet script and may not necessarily correlate with the intended behavior of the http method being used. Although it is not good practice, your RESTlet could define a get entry point function that creates data rather than retrieves it. Similarly, whether a method requires data varies depending on how you write the function. You could write a post entry point function that does not require input. Although, that is also not best practice.

Input Data Is Handled Differently by Different HTTP Methods

Input parameters to RESTlet entry points are handle differently based on the entry point.

The way you pass input parameters to a RESTlet varies depending on the http method you use:

HTTPS Methods for Secure Communication Between SuiteScripts and REST Endpoints

Starting in NetSuite 2020.2, interoperability between SuiteScript scripts, RESTlets, and SuiteTalk REST endpoints is improved by allowing authentication for an already established session to be passed using an https call. Previously, when an https call was used from one NetSuite script type to another, users had to reauthenticate in the second script even though they were still logged in to NetSuite.Now there are two new N/https methods that don’t require reauthentication:

This new solution replaces the possible need to use Suitelets with Available without login and Execute as Role of Administrator to communicate between a SuiteScript script and a RESTlet or a REST API.

Note:

These new methods are for calling the RESTlet internal to NetSuite and not from an external application or other source.

Related Topics

SuiteScript 2.x RESTlet Reference
Deploying a RESTlet
Identifying a RESTlet in a Call
Selecting an HTTP/HTTPS Method for Calling a RESTlet
Creating a Content–Type Header
SuiteScript 2.x RESTlet Error Handling
RESTlet Governance and Security

General Notices