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.

·3 min read·4 views·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescription
options.methodenumrequiredSpecifies the HTTP method to be used (GET, POST, etc.) as defined in http.Method.
options.urlstringrequiredThe HTTP URL that the request will target.
options.bodystringObjectoptional
options.headersObjectoptionalAn object defining custom headers to be included in the request.

Errors

During the request process, several error codes may be encountered:

Error CodeMessageThrown If
SSS_INVALID_HOST_CERTAn 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_URLThe URL provided must be a fully qualified HTTP/HTTPS URL.The URL in options.url is improperly formatted.
SSS_MISSING_REQD_ARGUMENTMissing 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:

suitescript
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: headerObj
12});
13...
14// Add additional code

Related 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?
Yes, the N/http module can be used in both client and server scripts since version 2015.2, allowing developers to create versatile integrations.
What are the required parameters for sending an HTTP request using the N/http module?
The mandatory parameters when sending an HTTP request are `options.method` for the HTTP method and `options.url` for the target URL. Both parameters must be specified for a successful request.
How does governance affect the usage of the N/http module in a script?
Each HTTP request made using the N/http module consumes 10 governance units, requiring careful management, especially in scripts running at scale to avoid exhausting governance limits.
What error could occur if I do not specify the URL correctly in my HTTP request?
If the URL is improperly formatted, the error `SSS_INVALID_URL` will be triggered, indicating that the URL must be fully qualified and structured correctly.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in SuiteScript

View all SuiteScript articles →