nlapiRequestRestlet(scriptId, deploymentId, urlParams, body, headers, httpMethod)

Note:

The content in this help topic pertains to SuiteScript 1.0. You can use this function in SuiteScript 1.0 scripts to call RESTlets written in SuiteScript 2.x code. For more information, see Using SuiteScript 2.x Scripts with SuiteScript 1.0 Scripts.

For information about SuiteScript 1.0, see SuiteScript 1.0 Documentation.

Description

Sends an HTTPS request to a RESTlet and returns the response. Authentication headers are automatically added.

The RESTlet runs with the same privileges as the calling script.

If you use custom headers, make sure the names of these headers do not contain underscores.

Returns

nlobjResponse object

Supported Script Types

Server scripts

Governance

10 units

Since

2023.1

Parameters

Parameter

Type

Required / Optional

Description

Since

scriptId

string | number

required

The internal ID or script ID of the script record.

Specify internal ID as a number. Specify script ID as a string.

2023.1

deploymentId

string

required

The script ID of the script deployment record.

2023.1

urlParams

Object<string, string>

optional

The parameters to be appended to the target URL as a query string.

2023.1

body

string | Object<string, string>

required, if httpMethod is POST or PUT.

The PUT/POST data.

This parameter is ignored if httpMethod is not POST or PUT.

2023.1

headers

Object<string, string>

optional

The HTTPS headers.

2023.1

httpMethod

string

optional

The HTTPS method (DELETE, GET, HEAD, POST, PUT).

The default value is GET if body is not specified, or POST if body is specified.

2023.1

Errors

Error Code

Message

Thrown If

INVALID_SCRIPT_DEPLOYMENT_ID_1

The deploymentId parameter does not reference a valid deployment for the script.

SSS_AUTHORIZATION_HEADER_NOT_ALLOWED

The authorization header is set.

SSS_INVALID_HEADER

The headers parameter is in an invalid format or contains an invalid header.

SSS_INVALID_SCRIPT_ID_1

The scriptId parameter does not reference a RESTlet script.

SSS_INVALID_URL_PARAMS

The urlParams parameter is in an invalid format.

SSS_MISSING_REQD_ARGUMENT

Missing a required argument: {param name}

The body, deploymentID, or scriptID parameter is not specified.

SSS_REQUEST_LOOP_DETECTED

The script executes a recursive function that has exceeded the limit for the number of times a script can call itself using an HTTPS request.

Syntax

            // Add additional code
...
var myRestletHeaders = {
    myHeaderType: 'Test',
    myHeaderStuff: 'This is my header',
    myHeaderId: 7
};
var myUrlParameters = {
    myFirstParameter: 'firstparam',
    mySecondParameter: 'secondparam'
}
var myRestletResponse = nlapiRequestRestlet(
    99, 
    'deploy1', 
    myUrlParameters, 
    'My Restlet body', 
    myRestletHeaders, 
    'GET'
); 

          

General Notices