Martí B Posted September 12 Report Share Posted September 12 Hi, I've been trying to make an api call in php to delete a client using its client id, but it's not working even though I've checked as many resources available as possible. The PHP code I'm using is: $query=$email; $response = $api->get("clients", "search", array('query'=>$query)); $client = $response->response(); $response_decoded = $response->response(); echo "\n".json_encode($response_decoded); $client = $client[0]; $user_id = intval($client->id_value); echo "<br>Client ID: $user_id"; //outputs "4983" (client id of the client account I'm using for testing) $response = $api->delete("clients", "delete", array($user_id)); print_r($api); $response_decoded = $response->response(); echo json_encode($response_decoded); And it's returning the following error: "Too few arguments to function Clients::delete(), 0 passed in \/path\/to\/blesta\/installation\/app\/controllers\/api.php on line 154 and exactly 1 expected However, print_r($api) prints: BlestaApi Object ( [url:BlestaApi:private] => api_url [user:BlestaApi:private] => api_user [key:BlestaApi:private] => api_key [last_request] => Array ( [url] => https://path/to_blesta/api/clients/delete.json [args] => Array ( [0] => 4983 ) ) ) So it seems that there is indeed an argument passed. The API Docs, in Clients Class, say: Quote delete( integer $client_id ) Permanently removes a client from the clients table. CAUTION: Deleting a client will cause all invoices, services, transactions, etc. attached to that client to become inaccessible. Parameters $client_id The client ID to permanently remove from the system I've tried passing the $user_id (client id) without using an array, but another error suggests to use an array. What am I doing wrong? I've used the api for other cases and following the API docs all worked fine. Quote Link to comment Share on other sites More sharing options...
Martí B Posted September 13 Author Report Share Posted September 13 Well, I just ended up working with Blesta database in my server directly, much easier. Quote Link to comment Share on other sites More sharing options...
Paul Posted September 13 Report Share Posted September 13 Deleting a client within the interface also removes any/all data associated with that customer. Transactions, services, etc. Only clients with no active services or open invoices can be deleted via the UI. If you simply delete the client, you may be leaving orphaned data. I would recommend digging deeper into how the delete client code works, it's possible you need to perform some other steps also. Quote Link to comment Share on other sites More sharing options...
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.