Identifying a RESTlet in a Call

Before you can call a RESTlet, you must know how to identify it which will depend on whether the RESTlet is called internally or from an external source. In general, you use values from the script deployment record and in some cases, you may also have to use the ID value from the script record.

Internal Versus External Calls

The script and script deployment records include all the information you need to identify a RESTlet. However, the values you use to identify a RESTlet vary depending on the source of the call.

Script and Script deployment records for a RESTlet with ID and URL fields called out.

Source of the Call

Identify the RESTlet with:

An external client

A full URL, similar to the one shown on the script deployment record, in the External URL field (callout 4). For details, see Dynamically Generating a Full URL.

A client SuiteScript with an active session in the same NetSuite account where the RESTlet is deployed

Either of the following:

  • The partial URL shown on the script deployment record, in the URL field (callout 3). For an example, see Example of a Client Script that Calls a RESTlet.

  • A URL generated by using the N/url module. To generate the URL this way, you need the script ID, which is viewable on the script record in the ID field (callout 1), in combination with the deployment ID, which is viewable on the script deployment record, in its ID field (callout 2). For an example, see Example of a Suitelet that Calls a RESTlet.

A server SuiteScript in the same NetSuite account where the RESTlet is deployed

A full URL, similar to the one shown on the script deployment record, in the External URL field callout (4). This URL must be dynamically generated, in one of the following ways:

  • By using the REST roles service. For details, see The REST Roles Service.

  • A URL generated by using the N/url module. To generate the URL this way, you need the script ID, which is viewable on the script record in the ID field (callout 1), in combination with the deployment ID, which is viewable on the script deployment record, in its ID field (callout 2). For an example, see Example of a Suitelet that Calls a RESTlet.

A server SuiteScript in a different NetSuite account from where the RESTlet is deployed

A full URL, similar to the one shown on the script deployment record, in the External URL field (callout 4). This URL must be dynamically generated by using the REST roles service. For details, see Dynamically Generating a Full URL.

Note:

If you are calling a RESTlet by using the delete or get method, you must extend the URL to include any input data that is required by the RESTlet’s logic. For details, see Selecting an HTTP/HTTPS Method for Calling a RESTlet.

Dynamically Generating a Full URL

When you save a script deployment record for a RESTlet, the system automatically generates a full URL that can be used to call the RESTlet. This value is shown in the External URL field of the script deployment record. However, in general, you should not hard-code this URL in a script, or in any other part of your integration. Instead, you should create logic that dynamically generates the portion of the URL that represents the RESTlet domain.

You can do this using one of the following approaches:

Note:

As of 2017.2, account-specific domains are supported for RESTlets, and you can access your RESTlet domain at the following URL, <accountID>.restlets.api.netsuite.com. The data center-specific domains supported before 2017.2 will continue to be supported. For more information, see URLs for Account-Specific Domains.

Related Topics

SuiteScript 2.x RESTlet Reference
Deploying a RESTlet
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