https.post(options)
Method Description |
Sends an HTTPS POST request.
Important:
If negotiating a connection to the destination server exceeds 5 seconds, a connection timeout occurs. If transferring a payload to the server exceeds 45 seconds, a request timeout occurs. |
Returns |
|
Supported Script Types |
Client and server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
10 units |
Module |
|
Since |
2015.2 |
Parameters
The options
parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
Since |
---|---|---|---|---|
|
string | Object |
required |
The POST data.
Note:
Sending a file using multipart/form-data content type in the |
2015.2 |
|
string |
required |
The HTTP URL being ‘posted’ to.
Note:
NetSuite does not automatically escape special characters reserved for use in URLs. If your URL includes reserved special characters, you will need to escape them. You can use an https.SecureString to specify the For more information about special characters in URLs see https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding or https://developers.google.com/maps/url/-encoding. For information about resolving a URL, see N/url Module. For information about getting the URL for a script, including Suitelets, see url.resolveScript(options). |
2015.2 |
|
string[] |
optional |
An array of string GUIDs. These GUIDS are searched for in the |
2015.2 |
|
Object |
optional |
The HTTPS headers. For more information, see HTTPS Header Information. |
2015.2 |
Errors
Error Code |
Message |
Thrown If |
---|---|---|
|
An untrusted, unsupported, or invalid certificate was found for this host. |
The client and server could not negotiate the desired level of security. The connection is no longer usable. You may also receive this error if the domain name in the
|
|
The URL must be a fully qualified HTTP/HTTPS URL. |
The URL specified in the For information about resolving a URL, see N/url Module. |
|
Missing a required argument: {param name}. |
The |
|
This script executes a recursive function that has exceeded the limit for the number of times a script can call itself using an HTTP request. Please examine the script for a potential infinite recursion problem. |
A script is calling back into itself recursively using an HTTP/HTTPS request. |
Syntax
The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/https Module Script Samples.
// Add additional code
...
var headerObj = {
name: 'Accept-Language',
value: 'en-us'
};
var response = https.post({
url: 'https://www.testwebsite.com',
body: 'My POST Data',
headers: headerObj
});
var myresponse_body = response.body; // see https.ClientResponse.body
var myresponse_code = response.code; // see https.ClientResponse.code
var myresponse_headers = response.headers; // see https.Clientresponse.headers
...
// Add additional code
Code Samples
The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/https Module Script Samples.
Sending a string data
// Add additional code
...
const response = https.post({
url: 'https://www.testwebsite.com',
body: "this is a string"
});
const responseBody = response.body; // For example "<html>..." (see https.ClientResponse.body)
const responseCode = response.code; // For example 200 (see https.ClientResponse.code)
const responseHeaders = response.headers; // For example { Content-Type: "text/plain" } (see https.Clientresponse.headers)
...
// Add additional code
Sending an object data
You can only pass an object for `Content-Type: application/x-www-form-urlencoded` requests. Refer to HTTPS Header Information.
// Add additional code
...
const objData = {
a: 1,
b: 2,
c: 3
};
const response = https.post({
url: 'https://www.testwebsite.com',
body: objData // a=1&b=2&c=3
});
...
// Add additional code
Sending a JSON data
For any other request, you need to stringify the data first.
// Add additional code
...
const jsonData = {
field1: "value1",
field2: "value2"
};
const headerObj = {
"Content-Type": "application/json"
}
const response = https.post({
url: 'https://www.testwebsite.com',
body: JSON.stringify(jsonData), // {"field1":"value1","field2":"value2"}
headers: headerObj,
});
...
// Add additional code
Sending a file in the body is not officially supported. However you can always build the request body manually:
// Add additional code
...
const fileObj = file.load({
id: 'SuiteScripts/testfile.csv'
});
const boundary = 'someuniqueboundaryasciistring';
const headerObj = {
'Content-Type': 'multipart/form-data; boundary=' + boundary
}
// Build the body manually
const body = [];
body.push('--' + boundary);
body.push('Content-Disposition: form-data; name="testfile"' + '; filename="' + fileObj.name + '"');
body.push('Content-Type: text/csv;charset=');
body.push('');
body.push(fileObj.getContents());
body.push('--' + boundary + '--');
body.push('');
const response = https.post({
url: 'https://www.testwebsite.com',
body: body.join('\r\n'),
headers: headerObj,
});
...
// Add additional code