Versions Compared

Key

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

...

Info
titleRequesting Models of Plugins

To request a specific model of a plugin format your request as /plugin.model/method.format

Formats

The API supports XML, JSON, and PHP serialization formats. By default JSON formatting is used. So if there is an error detecting the format of the request (due to a bad URL, for example) the error response will be returned in JSON format.

...

  1. Sending invalid parameters will result in a 400 Bad Request response.

    No Format
    HTTP/1.1 400 Bad Request
    Content-Length: 161137
    
    {
     "model":
     {
      "message":"The request cannot be fulfilled due to bad syntax.",
      "errors":
      {
       "field":
       {
        "code":"Error message."
       }
      }
     }
    }
  2. Providing invalid credentials will result in a 401 Unauthorized response.

    No Format
    HTTP/1.1 401 Unauthorized
    Content-Length: 67
    
    {"message":"The authorization details given appear to be invalid."}
  3. Attempting to access a resource that is not callable will result in a 403 Forbidden response.

    No Format
    HTTP/1.1 403 Forbidden
    Content-Length: 55
    
    {"message":"The requested resource is not accessible."}
  4. Attempting to access a resource that does not exist will result in a 404 Not Found response.

    No Format
    HTTP/1.1 404 Not Found
    Content-Length: 52
    
    {"message":"The requested resource does not exist."}
  5. Requesting a format that is not supported will result in a 415 Unsupported Media Type response.

    No Format
    HTTP/1.1 415 Unsupported Media Type
    Content-Length: 66
    
    {"message":"The format requested is not supported by the server."}
  6. If an unexpected error occurs a 500 Internal Server Error will result. If this error is encountered consult the documentation for the method you are requesting.

    No Format
    HTTP/1.1 500 Internal Server Error
    Content-Length: 42
    
    {"message":"An unexpected error occured."}
  7. When Blesta is under maintenance mode, the API will return a 503 Service Unavailable response.

    No Format
    HTTP/1.1 503 Service Unavailable 
    Content-Length: 81 
    
    {"message":"The requested resource is currently unavailable due to maintenance."}

...

Code Block
languagephp
titleConnecting Remotely
firstline1
linenumberstrue
<?php
// The URL to the API
$api_url = "https://yourdomain.com/installpath/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 = "json";

// 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;
?>
Info
titleDownload the API SDK

The SDK includes an API processor that makes it super easy to work with the API.

 

Locally

Using the Command Line Interface

...