HTTP Request Handling in SuiteScript 2.x: Parameters and
Learn to manage HTTP requests in SuiteScript 2.x, covering parameters, syntax, errors, and best practices for efficient integration.
TL;DR Opening
This article explains how to send HTTP requests in SuiteScript 2.x, detailing required parameters, syntax, potential errors, and governance. Understanding this feature is crucial for developers integrating external services within NetSuite applications.
Method Description
The HTTP request handling in SuiteScript 2.x allows developers to send HTTP requests programmatically. However, there are important timeouts to consider: if it takes longer than 5 seconds to connect to the destination server, the connection will time out. Similarly, if the request payload transmission exceeds 45 seconds, it will also time out. Keep in mind that this method does not work in unauthenticated client-side contexts.
Returns
The method returns either an http.ClientResponse or http.ServerResponse, facilitating the handling of responses from external servers.
Supported Script Types
This functionality is available in both client and server scripts. Developers can leverage various SuiteScript 2.x script types to implement this feature effectively.
Governance
Usage of this HTTP request method consumes 10 governance units, which is essential to consider when planning your scripts to avoid hitting governance limits.
Parameters
The options parameter is a JavaScript object that can include the following properties:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.method | enum | required | Specifies the HTTP method to be used (GET, POST, etc.) as defined in http.Method. |
options.url | string | required | The HTTP URL that the request will target. |
options.body | string | Object | optional |
options.headers | Object | optional | An object defining custom headers to be included in the request. |
Errors
During the request process, several error codes may be encountered:
| Error Code | Message | Thrown If |
|---|---|---|
SSS_INVALID_HOST_CERT | An untrusted, unsupported, or invalid certificate for the host was detected. | The client-server negotiation failed, often due to a domain issue in options.url. |
SSS_INVALID_URL | The URL provided must be a fully qualified HTTP/HTTPS URL. | The URL in options.url is improperly formatted. |
SSS_MISSING_REQD_ARGUMENT | Missing a required argument: {param name}. | Either options.method or options.url is not provided in the request. |
Syntax
The following code snippet illustrates the syntax for sending a simple HTTP request:
1// Add additional code 2...3var headerObj = {4 name: 'Accept-Language',5 value: 'en-us'6};7var response = http.request({8 method: http.Method.GET,9 url: 'http://www.google.com',10 body: 'My REQUEST Data',11 headers: headerObj12});13...14// Add additional codeRelated Topics
Key Takeaways
- The method enables HTTP requests with specific governance limits.
- Timing out can occur if connection or payload transmission exceeds set thresholds.
- Properly understanding parameters and error codes improves script reliability.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Does the N/http module support both client-side and server-side scripts in NetSuite?
What are the required parameters for sending an HTTP request using the N/http module?
How does governance affect the usage of the N/http module in a script?
What error could occur if I do not specify the URL correctly in my HTTP request?
Was this article helpful?
More in SuiteScript
- N/https Module: Binary File Support in NetSuite 2025.2
NetSuite 2026.1 adds binary file support to N/https for streamlined file handling.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
- Attach and Detach Operations in NetSuite 2026.1
Attach and detach operations for record relationships in NetSuite enhance data management and connectivity.
- Create-Form Operation in NetSuite 2026.1 REST Web Services
Create-form operation in NetSuite 2026.1 APIs streamlines record creation and enhances efficiency.
