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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category