CraigA Posted August 28, 2013 Report Posted August 28, 2013 Hello all, I'm trying to write something based on the API SDK $api = new BlestaApi($url, $user, $key); $response = $api->get("users", "getByUsername", array('username' => $_GET["username"])); $valid = $api->get("users","validatePasswordEquals", array('password' => $_GET["password"], 'user_id' => $response->response()->id)); //setCustomField( integer $field_id, integer $client_id, string $value ) //getCustomField( integer $field_id, integer $company_id = null ) $cf = $api->get("Clients","getCustomField", array('field_id' => 5)); print_r($response->response()); print_r($valid->response()); print_r($cf->response()); print_r($response->errors()); I'm pretty sure someone is going to tell me my logic is wrong here. Basically what I was going to do here is something along the lines of:if $valid->response() = 1 setCustomField(blah blah blah) The issue I'm having is although both the client_id and user_id exist in the 'clients' database table, I'm not sure how to equate the user_id to the client_id so that I can use the 'setCustomField' call. Any help/suggestions/reprimand for not doing this the correct way/pointers on how to do it the correct way? Thanks, Craig Quote
Tyson Posted August 28, 2013 Report Posted August 28, 2013 The user_id is a unique field per client. You can call Clients::getByUserId() to fetch the client. Something like the below may be what you're looking for: <?php ... $user = $api->get("users", "getByUsername", array('username' => $_GET['username']))->response(); if ($user) { $password_matches = $api->get("users", "checkPassword", array('password' => $_GET['password'], 'stored_hash' => $user->password))->response(); $client = $api->get("clients", "getByUserId", array('user_id' => $user->id))->response(); if ($password_matches && $client) { $api->post("clients", "setCustomField", array('field_id' => 5, 'client_id' => $client->id, 'value' => "my_new_value")); } } ... ?> CraigA and Michael 2 Quote
CraigA Posted August 28, 2013 Author Report Posted August 28, 2013 Ahhh I didn't see the getByUserid there, must've been too tired. Thanks a lot Tyson, exactly what I needed 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.