I'm trying to modify a custom entity API. Essentially, I want to take the data the API gets in the 'read' GET action and insert/change it's data directly.
Reasoning: I have a custom "License" ("CLicense") entity. This has a few fields that are stored in the Espo database. Some of the fields are flags (Boolean field types) that I want to update from a separate API every time the record is read/retrieved. So I want to be able to go to "...api/v1/CLicense/{id}" and have it retrieve the data that is stored in Espo's database, and update those specific fields with the data from the external API.
I've found some posts about how to get external databases to work with API routes, but those don't seem to help for what I'm trying to do. I've tried to change the "custom\Espo\Custom\Controllers\CLicense.php" file to extend from "Action", but that breaks it entirely (Not even an error response displayed, only logged). At this current point I have the "CLicense" controller being extended from "\Espo\Core\Templates\Controllers\Base", with a public function of "getActionTest" (my route is set to use this action for right now). In this function, I want to be able to get the record's data, get the data from the external API, then "merge" the two. I have not found any way that works to actually get the record's data here. I also can't get the request ID to read for some reason either.
"custom\Espo\Custom\Controllers\CLicense.php":
Reasoning: I have a custom "License" ("CLicense") entity. This has a few fields that are stored in the Espo database. Some of the fields are flags (Boolean field types) that I want to update from a separate API every time the record is read/retrieved. So I want to be able to go to "...api/v1/CLicense/{id}" and have it retrieve the data that is stored in Espo's database, and update those specific fields with the data from the external API.
I've found some posts about how to get external databases to work with API routes, but those don't seem to help for what I'm trying to do. I've tried to change the "custom\Espo\Custom\Controllers\CLicense.php" file to extend from "Action", but that breaks it entirely (Not even an error response displayed, only logged). At this current point I have the "CLicense" controller being extended from "\Espo\Core\Templates\Controllers\Base", with a public function of "getActionTest" (my route is set to use this action for right now). In this function, I want to be able to get the record's data, get the data from the external API, then "merge" the two. I have not found any way that works to actually get the record's data here. I also can't get the request ID to read for some reason either.
"custom\Espo\Custom\Controllers\CLicense.php":
PHP Code:
<?php
namespace Espo\Custom\Controllers;
use Espo\Core\Api\Action;
use Espo\Core\Api\Request;
use Espo\Core\Api\Response;
use Espo\Core\Api\ResponseComposer;
use Espo\Core\Record\Service;
use Espo\Core\Record\ServiceContainer;
class CLicense extends \Espo\Core\Templates\Controllers\Base
{
public function getActionTest(Request $request, Response $response) : Response
{
$service = $this->recordServiceContainer->get('CLicense');
$id = $request->getRouteParams('id');
// $id = '683dd946e1a0adbb7';
// $data = the record data from Espo
// return ResponseComposer::json($data);
}
}