N/http and N/https Support PATCH Method in NetSuite

N/http and N/https now support the PATCH method for API calls, enhancing integration in NetSuite.

·2 min read·8 views·View Oracle Docs

TL;DR Opening

N/http and N/https modules in NetSuite now support the PATCH method, enabling developers to perform updates directly via API calls. This enhancement is crucial for improving integration capabilities within applications, making it easier to modify existing resources.

What Changed?

Starting in the latest update, the method enumeration in both N/http and N/https modules includes the PATCH method. This addition allows users to make more granular updates to resources via external calls and Suitelet calls using the following functions:

  • http.request(options)
  • https.request(options)
  • https.requestSuitelet(options)
  • clientCertificate.request(options)

How to Use PATCH Method?

You can pass either http.Method.PATCH or https.Method.PATCH in any parameter that requires a method value. However, if a particular API endpoint does not permit the PATCH method, users will receive an HTTP 405 error indicating that the method is not allowed.

Important Considerations

  • Ensure that the options parameter (a JavaScript object) correctly contains the required fields to use the PATCH method:

    • options.method: required, must be set using either http.Method.PATCH or https.Method.PATCH.
    • options.url: required, this should be the URL to which the request is made.
    • options.body: optional, applicable only for PATCH requests alongside PUT and POST.
    • options.headers: optional, for specifying additional HTTP/S headers.
  • Timeouts: If a connection to the destination server takes longer than 5 seconds, a timeout will occur. Similarly, if the request payload takes longer than 45 seconds, the request will timeout. This means that good error handling is essential to manage these scenarios appropriately.

Example Usage

Here is a simple example of using the PATCH method with the N/http module:

javascript
1"text-purple-400">var http = "text-purple-400">require('N/http');
2
3"text-purple-400">var options = {
4 method: http.Method.PATCH,
5 url: 'https://api.example.com/resource/123',
6 body: JSON.stringify({ key: 'value' }),
7 headers: {
8 'Content-Type': 'application/json'
9 }
10};
11
12"text-purple-400">var response = http.request(options);

This example demonstrates how to send a PATCH request to update a specific resource identified by its ID. Always check the responses to ensure validation and handle any errors that may occur.

Who This Affects

  • Developers: Anyone developing or maintaining integrations with external services using the N/http or N/https modules will benefit from this feature.
  • Administrators: Those responsible for system integrations may need to review changes in API usage.

Key Takeaways

  • The PATCH method is now available in N/http and N/https modules.
  • It allows for partial updates to resources via API calls.
  • Ensure correct error handling for HTTP 405 responses when using PATCH.
  • Understand the timeout limits on request connections and payloads for efficient API interaction. Source: This article is based on Oracle's official NetSuite documentation.
Source: N/http and N/https Now Supports PATCH Method 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 →