mesino Posted October 1, 2018 Report Share Posted October 1, 2018 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. Quote Link to comment Share on other sites More sharing options...
0 mesino Posted October 2, 2018 Author Report Share Posted October 2, 2018 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. Quote Link to comment Share on other sites More sharing options...
0 Tyson Posted October 2, 2018 Report Share Posted October 2, 2018 Per CORE-1232, this is an issue with ionCube and won't be fixed in Blesta. Pass NULL for the key and iv to use the default system key. Quote Link to comment Share on other sites More sharing options...
0 mesino Posted October 3, 2018 Author Report Share Posted October 3, 2018 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 ) ) Quote Link to comment Share on other sites More sharing options...
0 Tyson Posted October 3, 2018 Report Share Posted October 3, 2018 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')); activa 1 Quote Link to comment Share on other sites More sharing options...
0 mesino Posted October 12, 2018 Author Report Share Posted October 12, 2018 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. Quote Link to comment Share on other sites More sharing options...
0 mesino Posted October 12, 2018 Author Report Share Posted October 12, 2018 Nevermind It was pretty easy. Blesta Addons 1 Quote Link to comment Share on other sites More sharing options...
Question
mesino
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:
gives expected results, for some reason:
fails with:
Will really appreciate some pointers. Thanks in advance.
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.