Asynchronous HTTP GET Requests in SuiteScript
Implement asynchronous HTTP GET requests in SuiteScript using promise-based syntax for effective APIs.
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:
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: 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 Get Request: ',20 details: reason21 });22 })23...24// Add additional codeThis 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://orhttps://. - The method will throw errors such as
SSS_INVALID_HOST_CERTif there are certificate issues orSSS_INVALID_URLif 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.promisemethod 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?
Can the http.get.promise method be used in both client-side and server-side scripts in NetSuite?
What happens if the URL for an HTTP GET request is improperly formatted when using the http.get.promise method?
Are there any additional requirements for the URL used in http.get.promise 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.
