Difference between revisions of "Template:API HTTP Example Boilerplate"

From SmartBots Developers Docs
Jump to: navigation, search
Line 10: Line 10:
  
 
   // Populate the query data
 
   // Populate the query data
   params += [
+
   list query = [
 
     "action="  + command,
 
     "action="  + command,
 
     "apikey="  + llEscapeURL(sbApiKey),
 
     "apikey="  + llEscapeURL(sbApiKey),
Line 17: Line 17:
 
   ];
 
   ];
  
   string query = llDumpList2String(params, "&");
+
   integer i;
 +
  for(i = 0; i<llGetListLength(params); i += 2) {
 +
    query += [ llList2String(params, i) + "=" + llEscapeURL(llList2String(params, i+1)) ];
 +
  }
 +
 
 +
  string queryString = llDumpList2String(query, "&");
 
   
 
   
 
   llHTTPRequest("http://api.mysmartbots.com/api/bot.html",
 
   llHTTPRequest("http://api.mysmartbots.com/api/bot.html",
     [HTTP_METHOD,"POST"], query);
+
     [HTTP_METHOD,"POST"], queryString);
 
}
 
}
  

Revision as of 21:58, 2 May 2017

/**
Send SmartBots HTTP API command.
*/
smartbotsAPI(string command, list params) {
  // You need to adjust the vars below:
  string sbApiKey = "...";
  string sbBotName = "...";
  string sbBotAccessCode = "...";

  // Populate the query data
  list query = [
    "action="  + command,
    "apikey="  + llEscapeURL(sbApiKey),
    "botname=" + llEscapeURL(sbBotName),
    "secret="  + llEscapeURL(sbBotAccessCode)
  ];

  integer i;
  for(i = 0; i<llGetListLength(params); i += 2) {
    query += [ llList2String(params, i) + "=" + llEscapeURL(llList2String(params, i+1)) ];
  }

  string queryString = llDumpList2String(query, "&");
 
  llHTTPRequest("http://api.mysmartbots.com/api/bot.html",
    [HTTP_METHOD,"POST"], queryString);
}

/*
Usage example:

smartbotsAPI("im", [
  "slname", "Glaznah Gassner",
  "message", "Hello in-world!"
]);
*/