Setting Response Headers in SuiteScript Server Scripts

Learn to set HTTP response headers in SuiteScript server scripts using the N/http module.

·2 min read·View Oracle Docs

The method for setting the value of an HTTP response header in SuiteScript allows developers to control header information sent by their applications. Understanding how to implement this functionality is crucial for enhancing interactivity and compliance with web standards.

Method Description

This method allows the setting of a response header's value, essential for providing additional information via HTTP responses. The usage of headers is common in web applications, helping to manage content negotiations and cache behaviors.

Supported Script Types

  • Server scripts only.

Governance

  • No governance limits apply.

Module

This functionality is part of the N/http Module.

Parent Object

This method is associated with the http.ServerResponse object.

Parameters

The method utilizes a single parameter — options, which is a JavaScript object containing the following attributes:

ParameterTypeRequired / OptionalDescription
options.namestringrequiredSpecifies the name of the header.
options.valuestringrequiredDefines the value to assign to the header.

Errors

Be aware of the following potential errors when using this method:

  • Error Code: SSS_INVALID_HEADER
    Message: One or more headers are not valid.
    Thrown If: The header name or value is invalid.

  • Error Code: SSS_MISSING_REQD_ARGUMENT
    Message: Missing a required argument: {param name}.
    Thrown If: Either options.name or options.value were not specified.

Syntax

The following code sample illustrates how to set an HTTP response header:

suitescript
// Set HTTP header
serverResponse.setHeader({
name: 'Accept-Language',
value: 'en-us',
});

This snippet demonstrates the syntax to invoke the method, which would be integrated into server-side scripts where the response is constructed.

Key Context

HTTP headers are crucial for transmitting additional information within requests and responses. They adhere to specific syntactical rules, such as not including underscores in custom header names. The headers not directly managed by application scripts include several restrictive elements typical in web protocols.

Related Topics

Important Note

Some HTTP headers cannot be set manually and will be ignored if specified. Notable blocked headers include Connection, Content-Length, and Host. When coding, always refer to the list of blocked headers to avoid unintentional issues in your applications.

Key Takeaways

  • Use the serverResponse.setHeader() method to manipulate HTTP response headers.
  • This method is only applicable within server scripts.
  • Pay attention to mandatory parameter specifications to avoid errors.
  • Certain HTTP headers cannot be configured, resulting in ignored values.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Is the setHeader method for setting HTTP headers in SuiteScript subject to any governance limits?
No, the setHeader method for setting HTTP headers in SuiteScript is not subject to any governance limits.
Which script types support the setHeader method for HTTP headers in NetSuite?
The setHeader method is supported only within server scripts in NetSuite.
What should I do if I encounter the 'SSS_INVALID_HEADER' error?
The 'SSS_INVALID_HEADER' error occurs if the header name or value is invalid. Ensure that both the header name and value conform to valid formats.
Can I manually set the 'Content-Length' header using the setHeader method in SuiteScript?
No, the 'Content-Length' header is among the HTTP headers that cannot be set manually and will be ignored if specified in SuiteScript.
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 Integration

View all Integration articles →