Get HTTP Response Header Values in SuiteScript
Retrieve values of HTTP response headers in SuiteScript, allowing for flexible header management in server scripts.
The getHeader method in SuiteScript provides a way to obtain the value(s) of a response header. If multiple values are associated with a header name, this method returns them as an array. This capability is essential for developers managing HTTP requests and responses in their scripts, particularly in server-side scripting contexts.
Method Description
The getHeader function allows you to extract the value or values of a specific HTTP response header from a server response object. This method can be particularly useful when dealing with web APIs or when you need to inspect or use response data for further processing.
Returns
- Type:
string | string[] - Returns a single string value if there is one header value, or an array if there are multiple values.
Supported Script Types
- Server scripts
Governance
- None
Module
- N/http Module
Parent Object
- http.ServerResponse
Parameters
The options parameter is a JavaScript object that requires the following:
| Parameter | Type | Required | Description |
|---|---|---|---|
| options.name | string | required | The name of the header to retrieve. |
Errors
The following error may be encountered if the required parameter is not provided:
- Error Code:
SSS_MISSING_REQD_ARGUMENT- Message: Missing a required argument: {param name}
- Thrown If: The
options.nameparameter is not specified.
Syntax Example
This code sample demonstrates how to use the getHeader method in a SuiteScript:
// Assuming serverResponse is definedconst acceptLanguageHeader = serverResponse.getHeader({ name: 'Accept-Language'});This function call retrieves the Accept-Language header from the server response. Ensure you include necessary additional code to manage the response appropriately.
Related Topics
- HTTP Header Information
- N/http Module
- ServerResponse Object Members
Key Takeaways
- Retrieve HTTP response header values using
getHeader()in SuiteScript. - Supports retrieval of single or multiple header values.
- Requires the header name as a mandatory parameter.
Frequently Asked Questions (4)
Can I use the getHeader method in client scripts?
What happens if I try to retrieve a header without specifying the header name in the getHeader method?
Is there a governance limit associated with using the getHeader method in SuiteScript?
Can getHeader return multiple values for a single header name?
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.
