Get Header Values from ServerResponse in SuiteScript

Easily retrieve HTTP header values with the ServerResponse object in SuiteScript, enhancing your script's communication capabilities.

·2 min read·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescriptionSince
options.namestringRequiredThe 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.name parameter is not specified.

Syntax

Here’s how to use the getHeader method:

suitescript
1// Sample code snippet to retrieve a header
2...
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

Key Takeaways

  • The getHeader method 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.

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

Frequently Asked Questions (4)

How do I retrieve multiple values for the same HTTP header using SuiteScript?
Use the `getHeader` method from the `ServerResponse` object. If the header has multiple values, they will be returned as an array, allowing you to handle them as needed.
What error will I encounter if I don't specify the header name in the getHeader method?
If the `options.name` parameter is not specified, the error `SSS_MISSING_REQD_ARGUMENT` will be thrown, indicating that a required argument is missing.
Is there any governance limitation associated with the getHeader method in SuiteScript?
No, there are no governance limitations applicable to the `getHeader` method in SuiteScript.
What script types support the getHeader method for retrieving HTTP header values?
The `getHeader` method is supported in server scripts within SuiteScript.
Source: Parameters 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 →