From SmartBots Developers Docs
Jump to: navigation, search

Retrieves data from a HTTP source using the POST method.

const queryData = { f: "123" };, queryData, "json")
	.then(function(response) {

// or with await:
const response = await, queryData, "json");

or with await:

var response = await, query);


This command accepts the following parameters:

Variable Required Description

url yes the URL to retrieve
queryData optional (object) the optional POST parameters, object
contentType optional (string) the optional content type (see below)

Function returns a Promise with the following data:
success bool true if command completed successfully
error string error string if command has failed
statusCode (on success) The HTTP status code
headers (on success) The array with HTTP headers
body (on success) The string body of the reply


This function makes an HTTP POST request to the specified URL. The query parameters may be added to the URL as a query object ({ param1: 1, param2: 2 }).

You can use to test your POST requests.


The length of the response body is limited to 4096 bytes.

Content type

By default the request is being sent as an old plain POST. This is the string composed of key=value pairs (also known as "application/x-www-form-urlencoded")., queryString);
// or, the same, queryString, "form");

You can change the request to send JSON by specifying "json" as contentType argument (this way is also known as "application/json"):, queryData, "json")


A simple POST request using await:

console.log("Doing http request...");

var response = await"", { param1: 1, param2: 2})
console.log("http result:", response.body);

// Gracefully stop the test script

A bit more complex example which provides the error handling (uses Promises but can be rewritten to use await):

console.log("Doing http request...");"", { param1: 1, param2: 2})
	.then(function(result) {
		if(!result.success) {
			// On error display the error message and stop the processing
			console.log("HTTP error:", result.error);
			throw "";
		console.log("http result:", result.body);

	.catch(function(err) {
		// This block allows cancelling the processing chain with throw ""
		if(err != "") { throw err; }
	.then(function() {
		// Gracefully stop the test script