Jump to content

Problem Editing Users Via The Api - Sql Syntax Error


Recommended Posts

Posted

Hello,

 

I'm attempting to edit users via the API and the source docs seem to be lacking a little in this area compared to the create user, so not sure if I have done something wrong...... but I'm basically doing this:

if (empty($user_data['country_iso'])) {
    // We can't pass in a state without a country, so make the state code empty as well
    $user_data['state_iso'] = '';
}

$data = array (
            'client_id' => $user_data['blesta_id'],
            'vars' => array (
                        'company' => $user_data['tax_company_name'],
                        'first_name' => $user_data['first_name'],
                        'last_name' => $user_data['last_name'],
                        'address1' => $user_data['address'],
                        'city' => $user_data['city'],
                        'zip' => $user_data['zip_code'],
                        'email' => $user_data['email'],
                        'numbers' => array (
                                        0 => array (
                                                'number' => $user_data['phone']
                                        )
                                    )
                    )
        );

if (!empty($user_data['country_iso'])) {
    // Add country
    $data['vars']['country'] = $user_data['country_iso'];
}

if (!empty($user_data['state_iso'])) {
    // Add country
    $data['vars']['state'] = $user_data['state_iso'];
}

$this->api->put("clients", "edit", $data);

$this->api points to the Blesta SDK.

 

This is the error output I get back:

object(stdClass)[9]
  public 'error' => 
    object(stdClass)[10]
      public 'message' => string 'An unexpected error occured.' (length=28)
      public 'response' => string 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id` = '16'' at line 1' (length=219)

Am I passing in the data wrong or doing something incorrectly? Is there a way I can make Blesta output the query it is trying to run?

 

Thanks!

Posted

Hmmm ok. So a client I created with clients::create I need to use contacts::edit and NOT clients::edit to edit their details?

You can edit a client via Clients::edit, but most information related to a client (e.g. first name, email, address, etc.) belongs to the primary contact. Each client has a contact (i.e. contact type is 'primary'), but it's also possible to add additional contacts under each client.

Posted

You can edit a client via Clients::edit, but most information related to a client (e.g. first name, email, address, etc.) belongs to the primary contact. Each client has a contact (i.e. contact type is 'primary'), but it's also possible to add additional contacts under each client.

 

Ahh ok, makes sense. Thanks!

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...