🔌 API

Unable to Create User via WebService API - roleid Issue

👤 emaida
Q
Question
Hello everyone,
I'm trying to create a new user through the WebService API in Vtiger 8.3.0, but I'm encountering an issue with the roleid field. When I try to create a user with the following data:

$user_data = [
'user_name' => 'testuser1',
'user_password' => 'Test123!',
'confirm_password' => 'Test123!',
'first_name' => 'Test',
'last_name' => 'User',
'email1' => '
A
Community Solution
✓ Answered
# Fix for INVALID_ID_ATTRIBUTE: Id specified is incorrect error in Vtiger CRM

## Option 1: Modify include\Webservices\Utils.php
Replace the vtws_getIdComponents function with the following:

php
function vtws_getIdComponents($elementid){
return explode("x", $elementid);
}


## Option 2: Modify include\Webservices\LineItem\VtigerInventoryOperation.php
In the constructFocusObject method, add a conditional check for id:

### Original:
php
public function constructFocusObject($element) {

$focus = CRMEntity::getInstance($this->getMeta()->getTabName());
$fields = $focus->column_fields;

foreach ($fields as $fieldName => $fieldValue) {
$fieldValue = $element[$fieldName];
if (is_array($fieldValue)) {
$focus->column_fields[$fieldName] = $fieldValue;
} else if ($fieldValue !== null) {
$focus->column_fields[$fieldName] = decode_html($fieldValue);
}
}

$ids = vtws_getIdComponents($element['id']);
$focus->id = $ids[1];

return $focus;
}


### Updated:
php
public function constructFocusObject($element) {

$focus = CRMEntity::getInstance($this->getMeta()->getTabName());
$fields = $focus->column_fields;

foreach ($fields as $fieldName => $fieldValue) {
$fieldValue = $element[$fieldName];
if (is_array($fieldValue)) {
$focus->column_fields[$fieldName] = $fieldValue;
} else if ($fieldValue !== null) {
$focus->column_fields[$fieldName] = decode_html($fieldValue);
}
}

if ($element['id']) {
$ids = vtws_getIdComponents($element['id']);
$focus->id = $ids[1];
}

return $focus;
}
← Back to API Join to answer →