HTTP PUT Request Syntax in SuiteScript 2.0
Learn the syntax for making asynchronous HTTP PUT requests in SuiteScript 2.0, including parameters and error handling.
The HTTP PUT request method in SuiteScript 2.0 allows developers to send asynchronous HTTP requests with the ability to handle responses using promises. Understanding this syntax is essential for developers looking to integrate external APIs into their NetSuite applications effectively.
What is the HTTP PUT Request?
The HTTP PUT method is used to send updated information to a specified resource. In SuiteScript, this method can be used to transmit data to remote servers reliably. Here are key components you need to know:
Method Description
- Function: Sends an HTTP PUT request asynchronously.
- Returns: A
Promise Objectrepresenting the outcome of the request. - Governance: This method consumes 10 units of governance per call.
- Module: This function is part of the
N/http Module. - Supported Script Types: Both client-side and server-side scripts can utilize this method.
Parameters
The options parameter must be provided as a JavaScript object. Below are the key parameters you can use:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.body | string or Object | Required | The PUT data to be sent. |
options.url | string | Required | The HTTP URL being requested. |
options.headers | Object | Optional | The HTTP headers to include with the request. |
Example Syntax
The following code sample demonstrates how to structure an HTTP PUT request. Note that this example is focused on syntax and not a complete functional application.
1// Additional code ...2var headerObj = {3 name: 'Accept-Language',4 value: 'en-us'5};6http.put.promise({7 url: 'http://www.example.com',8 body: 'My PUT Data',9 headers: headerObj10})11 .then(function(response) {12 log.debug({13 title: 'Response',14 details: response15 });16 })17 .catch(function onRejected(reason) {18 log.debug({19 title: 'Invalid Request:',20 details: reason21 });22 });23// Additional code ...Error Handling
When using the HTTP PUT method, be aware of potential errors:
- SSS_INVALID_HOST_CERT: Thrown for untrusted or invalid certificate.
- SSS_INVALID_URL: Occurs if a malformed URL is specified.
By understanding the syntax and mechanics of the HTTP PUT request in SuiteScript 2.0, developers can effectively manage data flows between NetSuite and external web services, enhancing application integration capabilities.
Key Considerations
- Ensure that the connection times out appropriately (after 5 seconds to connect, and 45 seconds to send).
- This method is not suitable for unauthenticated client-side contexts.
Key Takeaways
- HTTP PUT requests allow asynchronous updates to resources in SuiteScript.
- Utilize promises for effective response handling.
- Important to manage errors and understand timeout limitations.
Frequently Asked Questions (4)
Does the HTTP PUT request method in SuiteScript 2.0 support both client-side and server-side scripts?
What happens if an invalid URL is specified in the HTTP PUT request?
How many governance units does an HTTP PUT request consume in SuiteScript 2.0?
What should be done to handle untrusted or invalid certificates in HTTP PUT requests?
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.
