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.

·2 min read·View Oracle Docs

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 Object representing 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:

ParameterTypeRequiredDescription
options.bodystring or ObjectRequiredThe PUT data to be sent.
options.urlstringRequiredThe HTTP URL being requested.
options.headersObjectOptionalThe 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.

suitescript
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: headerObj
10})
11 .then(function(response) {
12 log.debug({
13 title: 'Response',
14 details: response
15 });
16 })
17 .catch(function onRejected(reason) {
18 log.debug({
19 title: 'Invalid Request:',
20 details: reason
21 });
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.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Does the HTTP PUT request method in SuiteScript 2.0 support both client-side and server-side scripts?
Yes, the HTTP PUT request method can be utilized in both client-side and server-side scripts within SuiteScript 2.0.
What happens if an invalid URL is specified in the HTTP PUT request?
If a malformed URL is specified, the HTTP PUT request in SuiteScript 2.0 will throw an SSS_INVALID_URL error.
How many governance units does an HTTP PUT request consume in SuiteScript 2.0?
Each HTTP PUT request call in SuiteScript 2.0 consumes 10 units of governance.
What should be done to handle untrusted or invalid certificates in HTTP PUT requests?
Ensure that your requests are sent to trusted hosts with valid certificates, as the HTTP PUT method will throw an SSS_INVALID_HOST_CERT error for untrusted or invalid certificates.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →