HTTP POST Requests in SuiteScript without Authentication

Master HTTP POST requests in SuiteScript. Learn about syntax, parameters, errors, and best practices for effective scripting.

·3 min read·View Oracle Docs

Starting in SuiteScript 2.x, developers can send HTTP POST requests using the http module, which facilitates communication between NetSuite and external servers. This feature is crucial for integrating third-party services and exchanging data seamlessly.

Method Description

The method sends an HTTP POST request as specified by the developer.

Important:

  • Timeouts: Connections will timeout if it takes longer than 5 seconds to connect to the server. The request payload will time out after 45 seconds if data transfer exceeds this duration.
  • Unauthorized Use: This method cannot function in unauthenticated client-side contexts. For further details, consult the SuiteAnswers article on outbound HTTPS nuances.

Returns

The method returns either a http.ClientResponse or an http.ServerResponse object, allowing you to handle responses appropriately.

Supported Script Types

  • Client scripts
  • Server scripts

Governance

This method consumes 10 governance units, which is important to consider for script performance and limits.

Module

Utilizes the N/http Module for implementation.

Parameters

Below are the parameters that can be passed to the POST request:

ParameterTypeRequired / OptionalDescription
options.bodystringRequiredThe POST payload data. Note that sending files with multipart/form-data is not supported.
options.urlstringRequiredThe complete HTTP/HTTPS URL to the destination. Refer to the N/url Module for URL handling.
options.headersObjectOptionalCustom HTTP headers for the request.

Errors

Understanding possible error codes can help in debugging HTTP requests:

Error CodeMessageThrown If
SSS_INVALID_HOST_CERTAn untrusted, privileged, or invalid certificate.Security negotiation failure for the connection.
SSS_INVALID_URLThe URL must be a fully qualified HTTP/HTTPS URL.Given URL isn't properly formatted.
SSS_MISSING_REQD_ARGUMENTMissing a required argument.If options.body or options.url is not provided.
SSS_REQUEST_LOOP_DETECTEDA recursive function exceeds the allowed call limit.If the script recursively calls itself via HTTP requests.

Syntax Example

The following snippet illustrates how to set up an HTTP POST request in SuiteScript. Note that this is just a syntax template for educational purposes:

suitescript
1// Sample code snippet for POST request
2var headerObj = {
3 name: 'Accept-Language',
4 value: 'en-us'
5};
6var response = http.post({
7 url: 'http://www.testwebsite.com',
8 body: 'My POST Data',
9 headers: headerObj
10});
11
12var myresponse_body = response.body; // see http.ClientResponse.body
13var myresponse_code = response.code; // see http.ClientResponse.code
14var myresponse_headers = response.headers; // see http.Clientresponse.headers

Conclusion

Understanding how to utilize HTTP POST requests in SuiteScript is vital for developers needing to interact with external APIs securely and efficiently. Make sure to validate your parameters and handle potential errors appropriately to ensure smooth functionality.


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

Key Takeaways

  • POST Request Use: Use the http.post method in SuiteScript for sending data to external servers.
  • Error Handling: Pay attention to error codes for better debugging and resolve issues quickly.
  • Governance Units: Keep the governance unit consumption in mind to optimize script performance.

Frequently Asked Questions (4)

Can HTTP POST requests be executed in client-side scripts without authentication in SuiteScript?
No, HTTP POST requests cannot function unauthenticated in client-side contexts in SuiteScript. Refer to SuiteAnswers for more details on outbound HTTPS nuances.
What happens if the connection to the server times out during an HTTP POST request in SuiteScript?
Connections will timeout if it takes longer than 5 seconds to connect to the server, and the request payload will timeout after 45 seconds if data transfer exceeds this duration.
Are there any special considerations for the payload data type in SuiteScript HTTP POST requests?
Yes, while the POST payload data is required as a string, sending files with multipart/form-data is not supported.
How many governance units are consumed by sending an HTTP POST request using SuiteScript?
Sending an HTTP POST request using SuiteScript consumes 10 governance units. This is important for script performance and limits.
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 →