The Vtiger Rest API has a Revise method that allows you to retrieve user data. However, you may notice that the response includes the name of the picture in the imagename field, but no file content or file path itself. This means that without additional steps, you will not be able to display the user's avatar on your site.
Modifying the Retrieve.php file
To fix this situation, you need to make changes to the include/Webservices/Retrieve.php file. After the line $entity = $handler->retrieve($id); add the following block of code:
if ($entityName === 'Users' && $entity['imagename']) {
$recordIds = explode('x', $id);
$userModel = Users_Record_Model::getInstanceById($recordIds[1], $entityName);
$images = $userModel->getImageDetails();
if (isset($images[0])) {
$entity['image_details'] = $images[0];
}
}
This block of code checks if the entity is a user and if the user has an image. If it does, it retrieves the image details and adds them to the response.
Checking the result
After making these changes, in addition to the imagename field, you will see an image_details object in the response with the following content:
"image_details": {
"id": "78",
"orgname": "borka.jpeg",
"path": "storage/2023/May/week4/78",
"name": "borka.jpeg",
{ "url": "http://vtiger.test:8000/public.php?fid=78&key=ca0ed8e8892736515860bec11edb4b39"
}
You now have information about the image, including the URL to retrieve the image. Use this URL to display the user's avatar on your site.
With this small change to the Vtiger API, you have full control over the user's data, including the image. This allows you to create more complete and customized interfaces for your users.