N/http Module

Use the N/http module to make HTTP calls from server or client scripts. For client scripts, this module also provides the ability to make cross-domain HTTP requests using NetSuite servers as proxies.

All HTTP content types are supported.

                                   
Note:

The N/http module does not accept the HTTPS protocol. Use the N/https Module for that purpose.

In This Help Topic

HTTP Header Information

HTTP headers can be used to pass additional information with an HTTP request or response. Each HTTP header consists of its case-insensitive name followed by a colon (:), then by its value (without line breaks). If you use custom headers, make sure the names of these headers do not contain underscores. For a general list of all HTTP headers, visit http://developer.mozilla.org/en-US/docs/Web/HTTP/Headers.

Some headers are not supported in NetSuite and are blocked. These are listed below as either general HTTP headers or Suitelet response headers.

General Blocked HTTP Headers

Be aware that certain headers cannot be set manually when using the N/http module methods. If a script attempts to set values for any of the following headers, the values are discarded. These headers are listed in the following table.

  • Connection

  • Content-Length

  • Host

  • JSESSIONID

  • Trailer

  • Transfer-Encoding

  • Upgrade

  • Via

Suitelet Response HTTP Header Blocklist

In addition to the headers described in General Blocked HTTP Headers, certain headers cannot be set manually when interacting with the http.ServerResponse Objects sent by Suitelets. If a script attempts to set values for any of these headers, the system throws an SSS_INVALID_HEADER error. These headers are listed in the following table.

  • Allow

  • Content-Location

  • Content-MD5

  • Content-Range

  • Date

  • Location

  • Proxy-Authenticate

  • Public-Key-Pins

  • Public-Key-Pins-Report-Only

  • Retry-After

  • Server

  • Strict-Transport-Security

  • Upgrade-Insecure-Requests

  • Warning

  • WWW-Authenticate

N/http Module Members

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Object

http.ClientResponse

Object (read-only)

Server scripts

The response from the server to an HTTP client request (for example, http.get(options)).

http.ServerRequest

Object (read-only)

Server scripts

HTTP request information sent to an HTTP server. For example, a request sent to/received by a Suitelet or RESTlet.

http.ServerResponse

Object

Server scripts

The response from an HTTP server to an HTTP request. For example, a response from a Suitelet or RESTlet.

Method

http.delete(options)

http.ClientResponse or http.ServerResponse

Client and server scripts

Sends an HTTP DELETE request and returns the response.

http.delete.promise(options)

Promise Object

Client and server scripts

Sends an HTTP DELETE request asynchronously and returns the response.

http.get(options)

http.ClientResponse or http.ServerResponse

Client and server scripts

Sends an HTTP GET request and returns the response.

http.get.promise(options)

Promise Object

Client and server scripts

Sends an HTTP GET request asynchronously and returns the response.

http.post(options)

http.ClientResponse or http.ServerResponse

Client and server scripts

Sends an HTTP POST request and returns the response.

http.post.promise(options)

Promise Object

Client and server scripts

Sends an HTTP POST request asynchronously and returns the response.

http.put(options)

http.ClientResponse or http.ServerResponse

Client and server scripts

Sends an HTTP PUT request and returns the response.

http.put.promise(options)

Promise Object

Client and server scripts

Sends an HTTP PUT request asynchronously and returns the response.

http.request(options)

http.ClientResponse or http.ServerResponse

Client and server scripts

Sends an HTTP request and returns the response.

http.request.promise(options)

Promise Object

Client and server scripts

Sends an HTTP request asynchronously and returns the response.

Enum

http.CacheDuration

enum

Server scripts

Holds the string values for supported cache durations. Use this enum to set the value of the type parameter in ServerResponse.setCdnCacheable(options).

http.Method

enum

Server scripts

Holds the string values for supported HTTP requests. Use this enum to set the value of method parameter in http.request(options).

http.RedirectType

enum

Server scripts

Holds the string values for supported NetSuite resources that you can redirect to. Use this enum to set the value of the type parameter for ServerResponse.sendRedirect(options).

ClientResponse Object Members

The following members are called on the http.ClientResponse Object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Property

ClientResponse.body

string (read-only)

Server scripts

The client response body.

ClientResponse.code

number (read-only)

Server scripts

The client response code.

ClientResponse.headers

Object (read-only)

Server scripts

The client response headers.

ServerRequest Object Members

The following members are called on the http.ServerRequest Object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

ServerRequest.getLineCount(options)

number

Server scripts

Returns the number of lines in a sublist.

ServerRequest.getSublistValue(options)

string

Server scripts

Returns the value of a sublist line item.

Property

ServerRequest.body

string (read-only)

Server scripts

The server request body.

ServerRequest.files

Object (read-only)

Server scripts

The server request files.

ServerRequest.headers

Object (read-only)

Server scripts

The server request headers.

ServerRequest.clientIpAddress

String (read-only)

Server scripts

The remote client IP address.

ServerRequest.method

http.Method

Server scripts

The server request HTTP method.

ServerRequest.parameters

Object (read-only)

Server scripts

The server request parameters.

ServerRequest.url

string (read-only)

Server scripts

The server request URL.

ServerResponse Object Members

The following members are called on the http.ServerResponse Object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

ServerResponse.addHeader(options)

void

Server scripts

Adds a header to the response.

ServerResponse.getHeader(options)

string | string[]

Server scripts

Returns the value of a response header.

ServerResponse.renderPdf(options)

void

Server scripts

Generates and renders a PDF directly to the response.

ServerResponse.sendRedirect(options)

void

Server scripts

Sets the redirect URL by resolving to a NetSuite resource.

ServerResponse.setCdnCacheable(options)

void

Server scripts

Sets CDN caching for a period of time.

ServerResponse.setHeader(options)

void

Server scripts

Sets the value of a response header.

ServerResponse.write(options)

void

Server scripts

Writes information (text, xml, html) to the response.

ServerResponse.writeFile(options)

void

Server scripts

Writes a file to the response.

ServerResponse.writeLine(options)

void

Server scripts

Writes line information (text, xml, html) to the response.

ServerResponse.writePage(options)

void

Server scripts

Generates a page.

Property

ServerResponse.headers

Object (read-only)

Server scripts

The server response headers.

Related Topics

SuiteScript 2.x Modules
SuiteScript 2.x

General Notices