Name Return Value Description
SK.API(
   "authentication token",
   request_params
)




 

Constructor

The class is used for execute WebForce API calls.

The library is available everywhere within the WebForce context.

The authentication token can be null when the calls are executed in administrator mode. If it's null, the current session ID is used.

The request_params are a hash of parameters which are passed to Request.JSON

By default all API calls are executed asynchronously.

execute(
   "API command",
   {
      <param1>: <value1>,
      <param2>: <value2>,
      ...
   },
   callback
)
 

Executes the request.

The command parameters are a hash with key = parameter name, value = the appropriate value.

The callback has the following interface:
function( success, message, data )
where "success" is true or false, the "message" is used when success is false and the "data" is the value of the "data" key from the returned JSON by the API call.

buildRequest(
   command,
   params,
   callback
)

Request.JSON object which should be executed manually after that

Generates a MooTools Request.JSON object. The parameters are the same as for the "execute". Note that by default the request is using a "post" method, so make sure you invoke "send". If you set the method to be "get", you should invoke "get" to the Request.JSON object instance.

 

Examples
Getting all databases for an account

<script type="text/javascript">
   new SK.API(
      null, // Will use the current session ID
      null  // Leave the default properties
   ).execute(
      "db.get_all",
      {
          // No parameters for this API call
      },
      function( success, message, data ) {
         if ( ! success ) { alert( message ); return; }

         // Inject the name of each database in the "databases" div below
         data.databases.each( function( db ) {
            var name = db.name;
            new Element( 'div', { text: name } ).inject( $( 'databases' ) );
         } );
      }
   );
</script>
<div id="databases"></div>