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.
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:
{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:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.name | string | Required | The name of the header. |
options.value | string | Required | The value used to set the header. |
Errors
It's important to handle potential errors properly. Below are the specific error codes:
| Error Code | Message | Thrown If |
|---|---|---|
SSS_INVALID_HEADER | One or more headers are not valid. | The header name or value is invalid. |
SSS_MISSING_REQD_ARGUMENT | Missing 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:
1// Add additional code2...3serverResponse.addHeader({4 name: 'Accept-Language',5 value: 'en-us',6});7...8// Add additional codeThis 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]
Key Takeaways
- SuiteScript allows adding custom HTTP headers through the
addHeadermethod. - 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_HEADERandSSS_MISSING_REQD_ARGUMENTproperly.
Frequently Asked Questions (4)
Can the addHeader method be used in client scripts or is it limited to server scripts?
Do I need to consider governance limits when using the addHeader method in SuiteScript?
What happens if I forget to include the required options.name or options.value when using addHeader?
Is it possible to have multiple headers with the same name when using the addHeader method?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
