Jump to content

Api Help -- Matching User_Id To Client_Id... Or Different Logic?


CraigA

Recommended Posts

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

Link to comment
Share on other sites

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"));
    }
}
...
?>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...