ServerRequest Object Members in SuiteScript 2.0 API
The ServerRequest object in SuiteScript 2.0 API handles HTTPS request details, enabling streamlined communication with external services.
The ServerRequest object is a crucial component of the N/https module in SuiteScript 2.0, designed to facilitate HTTPS communication between your scripts and external servers or services. It's important for developers to understand its members and functionalities to effectively handle requests made to Suitelets or RESTlets.
What is the ServerRequest Object?
The ServerRequest object encapsulates specific details about an HTTPS request sent to a server. This includes request parameters, headers, and the body of the request, which can be utilized to process incoming client requests.
Key Features of the ServerRequest Object
Here are the primary members you can access in the ServerRequest object:
| Member Name | Type | Description |
|---|---|---|
ServerRequest.body | string (read-only) | Contains the body of the server request. |
ServerRequest.files | Object (read-only) | Represents uploaded files in ID-file pairs. |
ServerRequest.headers | Object (read-only) | Contains the request's headers. |
ServerRequest.method | https.Method | Specifies the HTTPS method (e.g., GET, POST) for the request. |
ServerRequest.parameters | Object (read-only) | Accesses the parameters sent with the request. |
ServerRequest.url | string (read-only) | Provides the URL of the server request. |
ServerRequest.getLineCount() | number | Returns the number of lines in a sublist. |
ServerRequest.getSublistValue() | string | Retrieves the value of a line item in a sublist. |
Best Practices
- Use Secure Connections: Always ensure your HTTPS requests are made over TLS 1.2 to guarantee security.
- Handle Errors: Script anomalies may arise, including failing requests. Utilize error handling mechanisms to manage such instances effectively.
- Understand the Available Methods: Familiarize yourself with methods such as
getSublistValueandgetLineCountto traverse and manipulate incoming request data effectively.
Conclusion
The ServerRequest object is a foundational element in managing HTTPS requests within SuiteScript 2.0. By leveraging its members correctly, developers can create robust applications that interact smoothly with external systems.
Key Takeaways
- The ServerRequest object provides essential request metadata for SuiteScripts.
- It defines properties to access headers, parameters, and the body of requests.
- Always ensure TLS 1.2 compliance for security in HTTPS calls.
Frequently Asked Questions (4)
Does the ServerRequest object apply to Suitelets, RESTlets, or both?
What permissions are required to access the ServerRequest object in SuiteScript 2.0?
Is the ServerRequest.method member able to handle all HTTP methods?
How can I handle errors when using the ServerRequest object?
Was this article helpful?
More in SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- SuiteScript 2.x Sublist Values: Standard and Dynamic Mode
Use setSublistValue in standard mode; select a line, set its current value and commit it in dynamic mode. Choose the API from the record's mode.
- SuiteScript Record.setValue: Body Fields, Types and Errors
Set NetSuite body fields with Record.setValue, matching field IDs and value types and checking common API errors.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
