Get HTTP Response Header Values in SuiteScript

Retrieve values of HTTP response headers in SuiteScript, allowing for flexible header management in server scripts.

·2 min read·View Oracle Docs

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:

ParameterTypeRequiredDescription
options.namestringrequiredThe 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.name parameter is not specified.

Syntax Example

This code sample demonstrates how to use the getHeader method in a SuiteScript:

suitescript
// Assuming serverResponse is defined
const 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

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

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?
No, the getHeader method is designed for use in server scripts only.
What happens if I try to retrieve a header without specifying the header name in the getHeader method?
If you do not specify the header name using the 'options.name' parameter, an error with code 'SSS_MISSING_REQD_ARGUMENT' will be thrown.
Is there a governance limit associated with using the getHeader method in SuiteScript?
No, there are no governance limits associated with using the getHeader method.
Can getHeader return multiple values for a single header name?
Yes, if a header has multiple values, the getHeader method returns them as an array; otherwise, it returns a single string.
Source: Syntax 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 Integration

View all Integration articles →