Get Header Values from ServerResponse in SuiteScript
Easily retrieve HTTP header values with the ServerResponse object in SuiteScript, enhancing your script's communication capabilities.
TL;DR Opening
This article explains how to retrieve HTTP header values using the ServerResponse object in SuiteScript. By utilizing the getHeader method, developers can easily access the headers from server responses, improving data management in their applications.
Method Description
The getHeader method returns the value or values of a specified response header. When multiple values are associated with the same header name, they are returned as an array, providing flexibility in handling various header formats.
Returns
- Type:
string|string[]
Supported Script Types
- Server scripts
For more information, refer to the SuiteScript 2.x Script Types.
Governance
- None applicable.
Parameters
The options parameter is a JavaScript object that contains the following key:
| Parameter | Type | Required / Optional | Description | Since |
|---|---|---|---|---|
options.name | string | Required | The name of the header to be retrieved. | 2015.2 |
Errors
The following error may be thrown if a required argument is missing:
- Error Code:
SSS_MISSING_REQD_ARGUMENT- Message: Missing a required argument: {param name}
- Thrown If: The
options.nameparameter is not specified.
Syntax
Here’s how to use the getHeader method:
1// Sample code snippet to retrieve a header2... 3serverResponse.getHeader({4 name: 'Accept-Language'5});6... Note: The above code snippet is illustrative. For functional examples, see the N/http Module Script Samples.
Related Topics
- http.ServerResponse
- HTTP Header Information
- N/http Module
- SuiteScript 2.x Modules
Key Takeaways
- The
getHeadermethod enables developers to access HTTP header values from a server response easily. - It supports multiple values for the same header, returning them as an array.
- Proper error handling ensures that required parameters are provided, enhancing script robustness.
- This functionality is available starting from SuiteScript version 2015.2.
Frequently Asked Questions (4)
How do I retrieve multiple values for the same HTTP header using SuiteScript?
What error will I encounter if I don't specify the header name in the getHeader method?
Is there any governance limitation associated with the getHeader method in SuiteScript?
What script types support the getHeader method for retrieving HTTP header values?
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.
