Asynchronous HTTP GET Requests in SuiteScript

Implement asynchronous HTTP GET requests in SuiteScript using promise-based syntax for effective APIs.

·2 min read·View Oracle Docs

The http.get.promise method in SuiteScript allows developers to send HTTP GET requests asynchronously, enabling better handling of API interactions without blocking execution. This method is particularly useful for both client-side and server-side scripts.

Key Features of the http.get.promise Method

  • Method Description: Sends an HTTP GET request asynchronously.
  • Return Type: Returns a Promise Object, allowing for asynchronous handling of responses.
  • Governance: The method consumes 10 governance units.
  • Supported Script Types: Compatible with both Client and Server scripts.

Syntax Overview

The following code sample illustrates how to use the http.get.promise method:

suitescript
1// Add additional code
2...
3var headerObj = {
4 name: 'Accept-Language',
5 value: 'en-us'
6};
7http.get.promise({
8 url: 'http://www.google.com',
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 Get Request: ',
20 details: reason
21 });
22 })
23...
24// Add additional code

This syntax highlights the essential components needed for crafting a GET request, including the URL and optional headers.

Important Notes

  • Ensure that the URL provided is fully qualified, meaning it must begin with http:// or https://.
  • The method will throw errors such as SSS_INVALID_HOST_CERT if there are certificate issues or SSS_INVALID_URL if the URL is improperly formatted.

Who This Affects

  • Developers: Those writing scripts that require API calls.
  • Administrators: Individuals managing integrations that rely on external data sources.

Key Takeaways

  • The http.get.promise method facilitates non-blocking API requests in SuiteScript.
  • Use promises for cleaner, more efficient asynchronous code management.
  • Proper URL formatting and header setup are crucial for successful calls.

Frequently Asked Questions (4)

Does using the http.get.promise method in SuiteScript consume a lot of governance units?
The http.get.promise method consumes 10 governance units per request.
Can the http.get.promise method be used in both client-side and server-side scripts in NetSuite?
Yes, the http.get.promise method is compatible with both Client and Server script types.
What happens if the URL for an HTTP GET request is improperly formatted when using the http.get.promise method?
If the URL is improperly formatted, the method will throw the `SSS_INVALID_URL` error.
Are there any additional requirements for the URL used in http.get.promise requests?
Yes, the URL must be fully qualified, meaning it must start with `http://` or `https://`.
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 →