Syleron Posted July 5, 2017 Report Posted July 5, 2017 I'm attempting to access support tickets via the API but no matter the request I keep getting the following error: object(BlestaResponse)#7 (2) { ["raw":"BlestaResponse":private]=> string(68) "{"message":"The requested resource does not exist.","response":null}" ["response_code":"BlestaResponse":private]=> int(404) } Example Request: function getTicket($id) { $data = [ 'ticket_id' => $id, 'get_replies' => true, 'reply_types' => null, 'staff_id' => null ]; $response = $this->api->get("support_manager.support_manager_tickets", "get", $data); var_dump($response); return $response; } Can someone please advise? Cheers Quote
Adam Posted July 6, 2017 Report Posted July 6, 2017 Syleron, This is a bug within Blesta and more so with minPHP. Great find. The issue is within app/controllers/api.php in the preAction function. The function tries to load the model from the url: support_manager.support_manager_tickets. app/controllers/api.php // Ensure that the request is formatted correctly if (isset($this->get[0]) && isset($this->get[1])) { $this->model = Loader::toCamelCase($this->get[0]); It calls Loader:toCamelCase which returns SupportManager.supportManagerTickets What is expected is the following format: SupportManager.SupportManagerTickets On the surface this should not have caused an issue as if you called a function like get_declared_classes() it would show up as a class that was loaded. However, the problem is the case sensitive does manner when the api class calls method_exists and Router::isCallable. The minPHP function toCamelCase does not account for periods in its algorithm. /** * Convert a string to "CamelCase" from "file_case" * * @param string $str the string to convert * @return string the converted string */ public static function toCamelCase($str) { if (isset($str[0])) { $str[0] = strtoupper($str[0]); } return preg_replace_callback( '/_([a-z])/', function ($c) { return strtoupper($c[1]); }, $str ); } The Blesta team will have a permanent fix in place as there are many ways to solve this. For now, the below patch file will get things working on your end. Apply the following patch file with patch(1): --- app/controllers/api.php 2017-03-14 10:23:18.000000000 -0700 +++ app/controllers/api.php 2017-07-05 21:35:18.337455862 -0700 @@ -68,7 +68,7 @@ // Ensure that the request is formatted correctly if (isset($this->get[0]) && isset($this->get[1])) { - $this->model = Loader::toCamelCase($this->get[0]); + $this->model = str_replace('_', '', ucwords($this->get[0], '_.')); $this->model_name = Loader::toCamelCase( strpos($this->model, '.') !== false ? ltrim(strrchr($this->model, '.'), '.') -Adam Michael and Syleron 2 Quote
Syleron Posted July 6, 2017 Author Report Posted July 6, 2017 @Adam Thank you so much! I appreciate the fix Quote
Blesta Addons Posted July 6, 2017 Report Posted July 6, 2017 calling the models like this will not lead a problem i think $response = $this->api->get("SupportManager.SupportManagerTickets", "get", $data); Michael 1 Quote
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.