Difference between revisions of "HTTP API/Doing HTTP API Calls"
Line 34: | Line 34: | ||
== Parsing HTTP Reply == | == Parsing HTTP Reply == | ||
− | HTTP APIs return | + | HTTP APIs return either JSON or URL-encoded string (by your choice). Use "dataType=json" input parameter. |
+ | |||
+ | === JSON (added Jan 2018) === | ||
+ | |||
+ | The reply is being returned as a JSON string: | ||
+ | |||
+ | <syntaxhighlight> | ||
+ | { | ||
+ | "result": "FAIL", | ||
+ | "resulttext": "BOT NOT EXISTS" | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === URL-encoded string === | ||
+ | |||
+ | The reply is being returned as a set of variables joined in the same way as URL parameters: | ||
<syntaxhighlight lang="http"> | <syntaxhighlight lang="http"> | ||
result=FAIL&resulttext=BOT%20NOT%20EXISTS | result=FAIL&resulttext=BOT%20NOT%20EXISTS | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | == Standard reply variables == | ||
There are two standard return variables: | There are two standard return variables: | ||
* '''result''' - takes one of two values:<br>OK - command completed successfully<br>FAIL - command failed | * '''result''' - takes one of two values:<br>OK - command completed successfully<br>FAIL - command failed | ||
− | * '''resulttext''' - contains the detailed | + | * '''resulttext''' - contains the detailed explanation of failed commands |
Other return variables may contain the query results (for example, "groups" for [[HTTP_API/Bot_Commands/listgroups|listgroups]]). | Other return variables may contain the query results (for example, "groups" for [[HTTP_API/Bot_Commands/listgroups|listgroups]]). |
Revision as of 08:59, 24 January 2018
To invoke HTTP API command, you have to call SmartBots API URL with required parameters. See the full list of HTTP Bot commands here.
The request can be either GET or POST. The returned value format is described down below.
API call constructor
https://www.mysmartbots.com/api/testing.html - compose and test API queries using simple web form
Passing parameters to API URL
Imagine you need to call say_chat_channel command to say something in local chat.
- Take the Bot API URL: https://api.mysmartbots.com/api/bot.html
- Add required parameters
- Parse the response
The resulting query looks like this:
string params = llDumpList2String([
"action=" + "say_chat_channel",
"apikey=" + llEscapeURL(yourApiKey),
"botname=" + llEscapeURL("YourBot Resident"),
"secret=" + llEscapeURL(botSecretCode),
"channel=" + "0",
"message=" + llEscapeURL("Hello there!")
],"&");
llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
[HTTP_METHOD,"POST"], params);
Parsing HTTP Reply
HTTP APIs return either JSON or URL-encoded string (by your choice). Use "dataType=json" input parameter.
JSON (added Jan 2018)
The reply is being returned as a JSON string:
{
"result": "FAIL",
"resulttext": "BOT NOT EXISTS"
}
URL-encoded string
The reply is being returned as a set of variables joined in the same way as URL parameters:
result=FAIL&resulttext=BOT%20NOT%20EXISTS
Standard reply variables
There are two standard return variables:
- result - takes one of two values:
OK - command completed successfully
FAIL - command failed - resulttext - contains the detailed explanation of failed commands
Other return variables may contain the query results (for example, "groups" for listgroups).
See also
Refer to HTTP API page for information on API commands available.