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.

·2 min read·View Oracle Docs

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:

ParameterTypeRequired / OptionalDescription
options.bodystringrequiredThe data to be sent in the PUT request.
options.urlstringrequiredThe target HTTP URL for the request.
options.headersObjectoptionalAny 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.url parameter.
  • SSS_MISSING_REQD_ARGUMENT: Indicates required parameters like options.body or options.url are missing.

Syntax Example

Below is a sample code snippet demonstrating the syntax for a basic PUT request:

suitescript
1// Example of an HTTP PUT request
2var 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: headerObj
11});

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.

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

Frequently Asked Questions (4)

What script types support the HTTP PUT request in the N/http Module?
The HTTP PUT request can be utilized in both client and server scripts within the SuiteScript framework.
What are the timeout settings for an HTTP PUT request in SuiteScript?
Connection attempts for an HTTP PUT request time out after 5 seconds if no response is received, and the request will time out if data transfer exceeds 45 seconds.
How many governance units does an HTTP PUT request consume in NetSuite?
Each HTTP PUT request consumes 10 governance units, which should be managed to avoid exceeding script execution limits.
What common errors should be anticipated when using the HTTP PUT request?
Common errors include SSS_INVALID_HOST_CERT for invalid host certificates, SSS_INVALID_URL for improperly formatted URLs, and SSS_MISSING_REQD_ARGUMENT if required parameters like 'options.body' or 'options.url' are missing.
Source: Parameters 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 →