Add HTTP Response Headers in SuiteScript for NetSuite
Add HTTP response headers in SuiteScript to enhance communication. 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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category