Versions Compared

Key

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

...

Note
titleRunning PHP in CGI or FCGId mode?

Update your .htaccess file to pass an environment variable to Blesta so it can capture the basic authentication details as per the following snippet:

Code Block
title.htaccess
RewriteEngine on
...
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


...

Section


Column
width50%


Code Block
languagephp
firstline1
titleConnecting Remotely with PHP
firstline1
linenumberstrue
<?php
require_once "blesta_api.php";

$user = "username";
$key = "key";
$url = "https://yourdomain.com/installpath/api/";

$api = new BlestaApi($url, $user, $key);

$response = $api->get("users", "get", array('user_id' => 1));

print_r($response->response());
print_r($response->errors());
?>



Column
width50%


Code Block
languagebash
titleConnecting Remotely with cURL
curl https://yourdomain.com/installpath/api/users/get.json?user_id=1 -u username:key



...

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
firstline
languagephp
firstline32
titleLoading Models from a Controller
32linenumberstrue
// from somewhere in your controller...
$this->uses(array("ModelName"));

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


Code Block
languagephp
firstline54
titleLoading Models elsewherefirstline54
linenumberstrue
// from any other class...
Loader::loadModels($this, array("ModelName"));

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

...