HTTP Headers in SuiteScript N/http Module Operations

Understand how to handle HTTP headers in SuiteScript using the N/http module, including limitations and read-only properties.

·2 min read·View Oracle Docs

HTTP headers play a crucial role in HTTP requests and responses made through the N/http module in SuiteScript. This article details how to effectively manage headers, addressing common errors and best practices, especially for developers working with HTTP communication in NetSuite.

What Are HTTP Headers?

HTTP headers are key-value pairs sent in an HTTP request or response. They provide essential information about the request or the object being sent. Each header can typically be referred to in both lower case and title case, although using all lower-case letters is recommended for accuracy and consistency. Additionally, when creating custom headers, avoid using underscores in header names for compatibility reasons.

Reserved Headers

One important note is that the Authorization header is reserved for OAuth authentication requests. Therefore, if you need to implement a different authentication mechanism, create a custom header such as X-Authorization.

Important: The headers and their values can change, so it’s your responsibility to test them to ensure they include the necessary information. For example, specific headers might be filtered when making an HTTP call to a Suitelet, affecting your request's behavior.

Read-Only Property Error

When dealing with HTTP headers, you may encounter the READ_ONLY_PROPERTY error. This error indicates that you attempted to modify a read-only property, which is not permitted. Understanding and handling these errors is essential for correct script performance.

Code Sample

Here’s a simple code snippet demonstrating how to log the server request headers:

suitescript
1// Add additional code
2...
3log.debug({
4 title: 'Server Request Headers',
5 details: request.headers
6});
7...
8// Add additional code

General Blocked HTTP Headers

Certain headers are blocked and cannot be manipulated when using the N/http module. If your script attempts to modify these specific headers, their values will be discarded. The blocked headers include:

  • Connection
  • Content-Length
  • Host
  • JSESSIONID
  • Trailer
  • Transfer-Encoding
  • Upgrade
  • Via

Understanding these limitations ensures effective handling of HTTP communications in your SuiteScript projects.

For more advanced integration and functionality, consider reviewing the N/http module in the official NetSuite documentation to better understand its capabilities and restrictions.

Key Takeaways:

  • HTTP headers are vital for managing requests/responses.
  • Use the N/http module for HTTP calls; custom headers should avoid underscores.
  • The Authorization header is reserved; utilize a custom prefix if needed.
  • Always test headers to ensure they're not filtered by NetSuite.
  • Manage read-only properties to avoid script errors.

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

Frequently Asked Questions (4)

How should I handle custom headers in the N/http module to ensure compatibility?
When creating custom headers in the N/http module, avoid using underscores in header names to maintain compatibility. It's also recommended to use all lower-case letters for consistency and accuracy.
What should I do if I encounter a READ_ONLY_PROPERTY error in my SuiteScript?
A READ_ONLY_PROPERTY error indicates an attempt to modify a read-only property. Make sure your script does not try to change any headers or properties that are meant to be unchangeable.
Are there any HTTP headers that are blocked in the N/http module and cannot be modified?
Yes, certain HTTP headers are blocked in the N/http module and cannot be modified. These include Connection, Content-Length, Host, JSESSIONID, Trailer, Transfer-Encoding, Upgrade, and Via.
Is the Authorization header available for custom authentication requests in the N/http module?
No, the Authorization header is reserved for OAuth authentication requests. For other authentication mechanisms, you should use a custom header, such as X-Authorization.
Source: Errors 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 →