Adding user avatar in Vtiger Rest API

Adding user avatar in Vtiger Rest API

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.

Popular Posts

My most popular posts

Maximum productivity on remote job
Business

Maximum productivity on remote job

I started my own business and intentionally did my best to work from anywhere in the world. Sometimes I sit with my office with a large 27-inch monitor in my apartment in Cheboksary. Sometimes I’m in the office or in some cafe in another city.

Hello! I am Sergey Emelyanov and I am hardworker
Business PHP

Hello! I am Sergey Emelyanov and I am hardworker

I am a programmer. I am an entrepreneur in my heart. I started making money from the age of 11, in the harsh 90s, handing over glassware to a local store and exchanging it for sweets. I earned so much that was enough for various snacks.

Hire Professional CRM developer for $25 per hour

I will make time for your project. Knowledge of Vtiger CRM, SuiteCRM, Laravel, and Vue.js. I offer cooperation options that will help you take advantage of external experience, optimize costs and reduce risks. Full transparency of all stages of work and accounting for time costs. Pay only development working hours after accepting the task. Accept PayPal and Payoneer payment systems. How to hire professional developer? Just fill in the form

Telegram
@sergeyem
Telephone
+4915211100235