HTTP PUT Request with N/http Module in SuiteScript
HTTP PUT requests in SuiteScript allow data transmission to servers, supporting both client and server scripts.
The HTTP PUT request in SuiteScript enables developers to send data to a specified server URL. This method is key for situations where data needs to be updated rather than just retrieved, allowing for seamless integration and interaction between client-side and server-side applications.
Method Description
The PUT request sends HTTP requests to update resources located at the specified destination URL. Key characteristics include:
- Timeouts: Connection attempts time out after 5 seconds if no response is received. Additionally, if data transfer exceeds 45 seconds, the request will time out.
- Context Requirements: This method cannot function in unauthenticated client-side contexts.
Returns
The response from the PUT method will return either an http.ClientResponse or http.ServerResponse, depending on the context of the script executing the request.
Supported Script Types
The PUT method can be utilized in both client and server scripts within the SuiteScript framework.
Governance
Each PUT request consumes 10 governance units, which should be taken into account to avoid exceeding limits during script execution.
Parameters
When crafting your PUT request, utilize the options parameter as a JavaScript object consisting of:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.body | string | required | The data to be sent in the PUT request. |
options.url | string | required | The target HTTP URL for the request. |
options.headers | Object | optional | Any custom HTTP headers to include. |
Error Handling
Knowing potential error codes can help troubleshoot issues effectively:
- SSS_INVALID_HOST_CERT: Occurs if the certificate for the host cannot be validated. Ensure the domain name is correct and uses valid syntax.
- SSS_INVALID_URL: Triggered by an invalid or improperly formatted URL in the
options.urlparameter. - SSS_MISSING_REQD_ARGUMENT: Indicates required parameters like
options.bodyoroptions.urlare missing.
Syntax Example
Below is a sample code snippet demonstrating the syntax for a basic PUT request:
1// Example of an HTTP PUT request2var headerObj = {3 name: 'Accept-Language',4 value: 'en-us'5};6 7var response = http.put({8 url: 'http://www.example.com/api/update',9 body: 'My PUT Data',10 headers: headerObj11});Remember, this snippet serves as a syntax reference and not a fully functional example. For comprehensive script examples, refer to the N/http Module documentation.
Related Topics
Key Takeaways
- The HTTP PUT method allows data updates to specified server URLs.
- Make sure to provide the required parameters to avoid errors.
- The method adheres to defined timeout policies for connections and data transfer.
- Governance units for each request are set at 10, impacting script usage.
Frequently Asked Questions (4)
What script types support the HTTP PUT request in the N/http Module?
What are the timeout settings for an HTTP PUT request in SuiteScript?
How many governance units does an HTTP PUT request consume in NetSuite?
What common errors should be anticipated when using the HTTP PUT request?
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.
