HTTP Request Parameters in SuiteScript for NetSuite
Learn about the parameters for HTTP requests in SuiteScript, including methods, URLs, and body content management.
The http.request method in SuiteScript enables developers to send HTTP requests. Understanding its parameters is essential for effective integration and interaction with external APIs.
How Does the HTTP Request Work?
The http.request method sends an HTTP request and the connection timeout settings are critical to note:
- The connection will time out if it exceeds 5 seconds.
- Request payloads must be completed within 45 seconds.
Keep in mind, this method is not usable in unauthenticated client-side contexts.
What Are the Supported Script Types?
This method can be utilized in both client and server scripts, making it versatile for different script types in the SuiteScript 2.x environment.
What Are the Governance Limits?
Each HTTP request operation consumes 10 governance units.
Parameters
The options parameter is required and must be a JavaScript object, containing the following fields:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.method | enum | Required | The HTTP request method, set using http.Method (e.g., GET, POST). |
options.url | string | Required | The fully qualified HTTP/HTTPS URL being requested. |
options.body | `string | Object` | Optional |
options.headers | Object | Optional | The HTTP headers to include with the request. |
What Errors Might Occur?
Several error codes can be returned to help diagnose issues when a request fails:
SSS_INVALID_HOST_CERT: A certificate issue is detected.SSS_INVALID_URL: The specified URL is not fully qualified.SSS_MISSING_REQD_ARGUMENT: Required parameters (options.methodoroptions.url) are missing.
Example Syntax
Here’s a basic example demonstrating how to structure an HTTP request using SuiteScript:
1var headerObj = {2 name: 'Accept-Language',3 value: 'en-us'4};5var response = http.request({6 method: http.Method.GET,7 url: 'http://www.google.com',8 body: 'My REQUEST Data',9 headers: headerObj10});This syntax allows for various configurations tailored to specific use cases by modifying the parameters provided.
Key Takeaways
- The HTTP request method requires specific parameters for functionality.
- Proper error handling is crucial for identifying issues related to requests.
- Governance units consumed during requests must be considered to avoid exceeding limits.
Frequently Asked Questions (4)
Does the N/http module support both client-side and server-side scripts?
What happens if my HTTP request takes longer than the specified timeouts?
Are there specific error codes I should be aware of when using the N/http module?
Do I need to handle errors when making HTTP requests with the N/http module?
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.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- 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.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category