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.
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:
1// Add additional code 2...3log.debug({4 title: 'Server Request Headers',5 details: request.headers6});7...8// Add additional codeGeneral 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:
ConnectionContent-LengthHostJSESSIONIDTrailerTransfer-EncodingUpgradeVia
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
Authorizationheader 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.
Frequently Asked Questions (4)
How should I handle custom headers in the N/http module to ensure compatibility?
What should I do if I encounter a READ_ONLY_PROPERTY error in my SuiteScript?
Are there any HTTP headers that are blocked in the N/http module and cannot be modified?
Is the Authorization header available for custom authentication requests in the N/http module?
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.
