Doing HTTP API Calls

From SmartBots Developers Docs
HTTP API
Revision as of 16:36, 29 June 2016 by Phil (Talk | contribs)

Jump to: navigation, search

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.

Passing parameters to API URL

Imagine you need to call say_chat_channel command to say something in local chat.

  1. Take the Bot API URL: http://api.mysmartbots.com/api/bot.html
  2. Add required parameters
  3. 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("http://api.mysmartbots.com/api/bot.html",
  [HTTP_METHOD,"POST"], params);

Parsing HTTP Reply

HTTP APIs return replies as a set of variables joined in the same way as URL parameters:

result=FAIL&resulttext=BOT%20NOT%20EXISTS

There are two standard return variables:

  • result - takes one of two values:
    OK - command completed successfully
    FAIL - command failed
  • resulttext - contains the detailed explaination of failed commands

Other return variables may contain the query results (for example, "groups" for listgroups).

Testing

Demo and testing

You can compose and test your queries using SmartBots API Testing Suite: http://www.mysmartbots.com/api/testing.html

The working demo of SmartBots API is available in our office. Read this article for details.

See also

Refer to HTTP API page for information on API commands available.