Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This document describes how to configure, connect to, and interact with the API. For information on expanding the API with your own custom code see Extending the API. All examples are presented using PHP.

Configuration

 

Authentication

The API supports Basic Authentication.

Connecting

There are a number of ways to connect to the API. Choose the option that best fits your environment.

...

Code Block
languagephp
titleConnecting Remotely
firstline1
linenumberstrue
<?php
// The URL to the API
$api_url = "https://yourdomain.com/installpath/index.php/api/";

// API credentials
$api_username = "username";
$api_key = "key";

// The Model to request
$model = "users";
// The method to request
$method = "get";
// The response format
$format = "xml";

// All parameters to send
$params = array(
 'user_id'=>1
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url . $model . "/" . $method . "." . $format . "?" . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $api_username . ":" . $api_key);

$result = curl_exec($ch);
echo $result;
?>

...

Locally

Using the Command Line Interface

...

If you're working with or have created code within the Blesta environment, there's no need to use the API at all. All of the methods available in the API are first and foremost available to Blesta, in the form of models. To use these models, simply load the model within your environment.

...

Code Block
languagephp
titleLoading Models from a Controller
firstline32
linenumberstrue
// from somewhere in your controller...
$this->uses(array("ModelName"));

// Now invoke it
$this->ModelName->someMethod($param1, $param2);
Code Block
languagephp
titleLoading Models elsewhere
firstline54
linenumberstrue
// from any other class...
Loader::loadModels($this, array("ModelName"));

// Now invoke it
$this->ModelName->someMethod($param1, $param2);

 

Requests