Jump to content
  • 0

"systemEncrypt" API call not working.


Question

Posted

Hi.

For some custom integration of Blesta, I have been trying the API examples listed here to make myself familiar with the API:

https://docs.blesta.com/display/dev/API

While:

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

gives expected results, for some reason:

$response = $api->post("encryption", "systemEncrypt", array('value' => "my text"));

fails with:

Class Object
(
    [error] => stdClass Object
        (
            [message] => An unexpected error occured.
            [response] => Internal error: Failed to retrieve the default value
        )
)

Will really appreciate some pointers. Thanks in advance.

6 answers to this question

Recommended Posts

  • 0
Posted

After some hit & trial and following hints on the API doc page, I realized that supplying values of optional arguments suppresses the error:

$response = $api->post("encryption", "systemEncrypt", array('value' => 'my text', 'key' => 'my key', 'iv' => 'my iv'));

works. Even blank values work:

$response = $api->post("encryption", "systemEncrypt", array('value' => 'my text', 'key' => '', 'iv' => ''));

As per the API and class docs, without the optional arguments, Blesta should encrypt/decrypt using the Blesta.system_key. But omitting these arguments results in an error as shown in the original post. Copy-pasting the system_key from config/blesta.php into 'key' and 'iv' values solves it for me and produces the desired result but this is far from ideal.

  • 0
Posted

Hi @Tyson

I had tried NULL but that also results in the same error:
 

<?php
require_once "blesta_api.php";

$user = "{API_USER}";
$key = "{API_USER}";
$url = "{API_URL}";

$api = new BlestaApi($url, $user, $key);
$response = $api->post("encryption", "systemEncrypt", array('value' => 'my text', 'key' => NULL, 'iv' => NULL));

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

Output:
 

Internal error: Failed to retrieve the default value

stdClass Object
(
    [error] => stdClass Object
        (
            [message] => An unexpected error occured.
            [response] => Internal error: Failed to retrieve the default value
        )

)

 

  • 0
Posted

It's unfortunate that even with null values set for the optional arguments it still fails.

An alternative would be to call a different API end point that wraps systemEncrypt. For example, you could create a simple plugin for Blesta that defines a model and method that returns the value of a call to systemEncrypt.

// Plugin model
class MyPluginEncryption extends MyPlugin
{
    public function encrypt($text)
    {
        return $this->systemEncrypt($text);
    }
}

Then, instead of calling systemEncrypt directly via the API, you call your plugin method instead.

// API request
$response = $api->post("MyPlugin.MyPluginEncryption", "encrypt", array('text' => 'test123'));

 

  • 0
Posted

Thanks. I am yet to learn plugin-creation on Blesta though :-(

Wish there existed a bare skeleton to start working on top of it. All such resources I could find on the web were for Blesta 3.x. 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...