HTTP Request Handling in SuiteScript 2.x: Parameters
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
- N/http Module
- SuiteScript 2.x Modules
- SuiteScript 2.x
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.
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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category