http.get

From SmartBots Developers Docs
Bot PlaygroundBuilt-in Functions
Revision as of 12:30, 14 July 2018 by Gg (Talk | contribs) (Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Retrieves data from a HTTP source.</onlyinclude> <syntaxhighlight lang="javascript"> http.get(url, query) .then(function(respon...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Retrieves data from a HTTP source.

http.get(url, query)
	.then(function(response) {
		...
	})
	.catch(function(err) {
		...
	});

Reference

This command accepts the following parameters:

Variable Required Description


Input:
url yes the URL to retrieve
query optional (object) the optional URL query string params


Output:
Function returns a Promise with the following data:
success bool true if command completed successfully
error string error string if command has failed
response The response object (body, serverCode, headers)

Comments

This function makes an HTTP GET request to the specified URL. The query string may be added to the URL (example.com/?param1=1&param2=2) or passes as a query object ({ param1: 1, param2: 2 }).

Example

console.log("Doing http request");

http.get("https://mysmartbots.com")
	.then(function(response) {
		console.log("http result:", response.body);
	})
	.catch(function(err) {
		console.log("error doing http:", err);
	});