Difference between revisions of "HTTP API"

From SmartBots Developers Docs
Jump to: navigation, search
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
HTTP API allows controlling SL groups and Second Life bots using HTTP queries. The query can be send from SL object (LSL script) or online.
+
HTTP API allows controlling your  Second Life bot using HTTP queries. The query can be send from SL object (LSL script), website code or your application.
  
== API Types ==
+
== The basics ==
  
There are two types of HTTP API at SmartBots. Open one of the following pages for complete list of the commands:
+
Basically the API usage consists of the following steps:
  
# [[HTTP API: Simple Groups]] API (easy-to-use API to control group invitations)
+
# Compose the query and send it (using '''llHTTPRequest''' in case of LSL)
# [[HTTP API: Bot Commands]] (complex routines to fully control your bot)
+
# Wait for the SmartBots reply (using '''http_response''' in case of LSL)
 +
# Decode the reply.
  
'''Simple Group API''' allows you sending group invitations, eject members by sending simple API commands. The return result of the API is a plain text.
+
Each SmartBots bot comes with HTTP API enabled. You just need to grab the [https://www.mysmartbots.com/docs/Bot_access_code bot's access code] (it is a kind of password for bot's API) and your unique [[HTTP_API/Developer's_API_key|Developer's API key]].
  
'''Bot API''' is slightly different: it provides more control over your bot, but you have to decode the API reply using llParseString2List and similar functions.
+
== API Testing Suite ==
  
== The basics ==
+
There's a special page to compose and test HTTP API queries: https://www.mysmartbots.com/api/testing.html
  
Basically the whole process consists of the following steps:
+
== Usage ==
 +
 
 +
=== Raw code ===
 +
 
 +
<syntaxhighlight lang="lsl">
 +
string params = llDumpList2String([
 +
  "action="  + "get_balance",
 +
 
 +
  "apikey="  + llEscapeURL(sbApiKey),
 +
  "botname=" + llEscapeURL(sbBotName),
 +
  "secret="  + llEscapeURL(sbBotAccessCode)
 +
], "&");
 +
 
 +
llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
 +
[HTTP_METHOD,"POST"], params);
 +
</syntaxhighlight>
 +
 
 +
Read [[HTTP_API/Doing_HTTP_API_Calls|Doing HTTP API Calls]] for more info.
 +
 
 +
=== Helper functions ===
 +
 
 +
We've written few helper functions to make HTTP API usage easier:
 +
 
 +
<syntaxhighlight lang="lsl">
 +
smartbotsAPI("status", []);
 +
</syntaxhighlight>
 +
 
 +
Check [[HTTP API/LSL Helper Functions|LSL Helper Functions]] for more info on helpers.
 +
 
 +
=== More examples ===
 +
 
 +
Check [[HTTP_API/Examples|HTTP API examples]] to see how HTTP API works in LSL.
  
# Compose the query string and send it using '''llHTTPRequest''' (either GET or POST).
 
# Pickup the SmartBots reply using '''http_response'''.
 
# Decode the reply.
 
  
Read [[Doing HTTP API Calls]] for more info.
 
 
{{NavMenu}}
 
{{NavMenu}}

Latest revision as of 15:46, 14 October 2019

HTTP API allows controlling your Second Life bot using HTTP queries. The query can be send from SL object (LSL script), website code or your application.

The basics

Basically the API usage consists of the following steps:

  1. Compose the query and send it (using llHTTPRequest in case of LSL)
  2. Wait for the SmartBots reply (using http_response in case of LSL)
  3. Decode the reply.

Each SmartBots bot comes with HTTP API enabled. You just need to grab the bot's access code (it is a kind of password for bot's API) and your unique Developer's API key.

API Testing Suite

There's a special page to compose and test HTTP API queries: https://www.mysmartbots.com/api/testing.html

Usage

Raw code

string params = llDumpList2String([
  "action="  + "get_balance",

  "apikey="  + llEscapeURL(sbApiKey),
  "botname=" + llEscapeURL(sbBotName),
  "secret="  + llEscapeURL(sbBotAccessCode)
], "&");

llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
 [HTTP_METHOD,"POST"], params);

Read Doing HTTP API Calls for more info.

Helper functions

We've written few helper functions to make HTTP API usage easier:

smartbotsAPI("status", []);

Check LSL Helper Functions for more info on helpers.

More examples

Check HTTP API examples to see how HTTP API works in LSL.