POST Request Parameters in SuiteScript for Integration

POST request parameters in SuiteScript allow server communication with HTTP. Learn about their types, required fields, and handling errors.

·2 min read·View Oracle Docs

The POST request parameters in SuiteScript play a crucial role in enabling seamless communication between your NetSuite account and external servers. This guide breaks down the fundamental elements needed to successfully utilize the POST method in SuiteScript's N/http Module.

What Are POST Request Parameters?

In SuiteScript, the POST method sends a request to a specified HTTP URL, facilitating data transfer to external services. It is vital for developers to understand the required parameters, how to handle errors, and the limitations of this functionality.

Key Characteristics of the POST Method

  • Timeouts: If the connection to the destination server takes longer than 5 seconds, it will timeout. Additionally, if it takes over 45 seconds to send the request payload, that too will timeout.
  • Script Types: This method is suitable for both client and server scripts but cannot run in unauthenticated client-side contexts.
  • Governance: This action consumes 10 governance units.

Parameters Overview

The options parameter is a JavaScript object that requires several key fields:

ParameterTypeRequired/OptionalDescription
options.bodystring or ObjectRequiredRepresents the POST data to be sent. Note that sending files using multipart/form-data is not supported in this parameter.
options.urlstringRequiredThe HTTP URL being requested. Must be a fully qualified URL to avoid SSS_INVALID_URL errors.
options.headersObjectOptionalAdditional HTTP headers to include with the request, if needed.

Handling Errors

When using the POST request, developers may encounter errors. Here are common error codes and messages:

  • SSS_INVALID_HOST_CERT: Thrown if an untrusted or invalid certificate is found for the host.
  • SSS_INVALID_URL: Indicates that the provided URL is not fully qualified.
  • SSS_MISSING_REQD_ARGUMENT: Occurs when the options.body or options.url parameter is missing.
  • SSS_REQUEST_LOOP_DETECTED: Triggered when a recursive function exceeds the limit for the number of calls made through an HTTP request.

Example Code Snippet

Here is a sample implementation of the POST request:

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

Conclusion

Understanding how to properly configure your POST request parameters is vital for successful integration in NetSuite environments. Be mindful of the constraints and error handling to ensure robust interactions with external web services.

Frequently Asked Questions (4)

Can POST requests in SuiteScript be executed in unauthenticated client-side contexts?
No, POST requests in SuiteScript cannot be executed in unauthenticated client-side contexts. They are suitable for both client and server scripts but require authentication.
What happens if the `options.url` parameter is not fully qualified?
If the `options.url` parameter is not fully qualified, it results in an `SSS_INVALID_URL` error. The URL must be fully qualified to avoid this error.
Is it possible to send files using multipart/form-data with the `options.body` parameter in SuiteScript's POST request?
No, sending files using multipart/form-data is not supported in the `options.body` parameter of SuiteScript's POST request.
What are the timeout constraints when sending POST requests via SuiteScript in NetSuite?
If a connection to the destination server takes longer than 5 seconds, it will timeout. Similarly, if sending the request payload takes over 45 seconds, it will also timeout.
Source: Parameters 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 →