Add HTTP Response Headers in SuiteScript for NetSuite

Add HTTP response headers in SuiteScript to enhance communication. This method supports custom headers for server responses.

·2 min read·View Oracle Docs

TL;DR Opening

Adding HTTP response headers in SuiteScript allows developers to customize server responses by transmitting additional information. This feature is essential for ensuring seamless application behavior and improving HTTP communication.

Method Description

The addHeader method is employed to add a header to the HTTP response. If the header has been previously set, the method appends another line for the same header. For example:

suitescript
{Vary: ['Accept-Language', 'Accept-Encoding']}

It’s crucial to note that the addHeader method does not return any value and is utilized in server scripts.

Supported Script Types

  • Server scripts: Utilize this method while programming in server contexts, especially while handling HTTP responses.

Governance

This method does not impose any governance limits, which means it can be executed without restrictions on usage counts.

Parent Object

The addHeader method belongs to the http.ServerResponse object, which is part of the N/http module in SuiteScript.

Parameters

The options parameter is a JavaScript object that includes the following:

ParameterTypeRequired / OptionalDescription
options.namestringRequiredThe name of the header.
options.valuestringRequiredThe value used to set the header.

Errors

It's important to handle potential errors properly. Below are the specific error codes:

Error CodeMessageThrown If
SSS_INVALID_HEADEROne or more headers are not valid.The header name or value is invalid.
SSS_MISSING_REQD_ARGUMENTMissing a required argument: {param name}.The options.name or options.value parameter is not specified.

Syntax

The following code snippet offers a basic illustration of the syntax:

suitescript
1// Add additional code
2...
3serverResponse.addHeader({
4 name: 'Accept-Language',
5 value: 'en-us',
6});
7...
8// Add additional code

This code sample serves as a template for implementing the addHeader method.

Related Topics

For further insights, review related topics:

  • [http.ServerResponse]
  • [HTTP Header Information]
  • [N/http Module]
  • [SuiteScript 2.x Modules]

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

Key Takeaways

  • SuiteScript allows adding custom HTTP headers through the addHeader method.
  • The method operates in server scripts and does not enforce governance limits.
  • Essential parameters include header name and value, both of which are mandatory.
  • Always handle potential errors like SSS_INVALID_HEADER and SSS_MISSING_REQD_ARGUMENT properly.

Frequently Asked Questions (4)

Can the addHeader method be used in client scripts or is it limited to server scripts?
The addHeader method is limited to server scripts and cannot be utilized in client scripts. It is specifically designed for handling HTTP responses in server contexts.
Do I need to consider governance limits when using the addHeader method in SuiteScript?
No, the addHeader method does not impose any governance limits, allowing it to be executed without restrictions on usage counts.
What happens if I forget to include the required options.name or options.value when using addHeader?
If you do not specify the required options.name or options.value, you'll encounter an error, specifically the SSS_MISSING_REQD_ARGUMENT error, indicating that a required argument is missing.
Is it possible to have multiple headers with the same name when using the addHeader method?
Yes, if a header with the same name is added again using the addHeader method, another line for the same header is appended, allowing multiple headers with the same name.
Source: Parameters 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 General

View all General articles →