Problem to access to Administration>Integrations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zkuun8
    Junior Member
    • Dec 2024
    • 24

    Problem to access to Administration>Integrations

    Hello,

    I try to build a module that use Administration>Integration datas.
    1) I've made a new section into Administration>Integration>MyCustomData
    2) I made a hook that need to use these datas.
    3) I get this error message when the hook is triggered :
    [2025-01-20 10:02:44] CRITICAL: (0) Could not load 'integration' service. :: POST /MgWorkspace :: /var/www/html/application/Espo/Core/Container.php(348)


    This is a part of my code :

    Code:
    <?php
    namespace Espo\Modules\CustomAPI\Hooks\MgWorkspace;
    
    use Espo\Core\Hooks\Base;
    
    class GeoserverSync extends Base
    {
        public function beforeSave(\Espo\ORM\Entity $entity, array $options = [])
        {
            if ($entity->isNew()) {
                $geoserverId = $this->createWorkspaceInCustomAPI($entity);
                $entity->set('CustomAPIId', $CustomAPIId);
            } else {
                $this->updateWorkspaceInCustomAPI($entity);
            }
        }
    
    private function getCustomAPIConfig()
    {
    // Récupère le container
    $container = $this->getContainer();
    
    // Récupère le service "integration" (et non "integrationManager")
    $integrationManager = $container->get('integration');
    
    // Récupère l'intégration "CustomAPI"
    $integration = $integrationManager->getIntegration('CustomAPI');
    
    // Renvoie la config
    return $integration->getConfig();
    }
    }


    Regarding the new version, would you recommand me to use Secrets instead of Integrations? if yes, should I add new fields to Secrets ? Or should I create 1 record per data I need to use ?


    Edit: this post should have been posted into Developper forum section.. sorry
  • yuri
    Member
    • Mar 2014
    • 8539

    #2
    Hi,

    $container->get('integration');

    This is a wrong usage. The container returns registered service objects. There's no 'integration' service (unless you would like to define it).

    There's the Integration entity type that we usually use to store arbitrary integration data in. No user-specific data through.

    You need to pass the entityManager to your hook in the constructor. Then fetch your integration entity. The entity ID is the name of the integration.

    $integation = $this->entityManager->getEntityById('IntegrationName');


    Though, you can use the new secrets feature.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • zkuun8
      zkuun8 commented
      Editing a comment
      About Secrets feature, could you please detail the logics : in which case you recommand to use Secrets instead of Integrations?
      thanks !
  • yuri
    Member
    • Mar 2014
    • 8539

    #3
    It's up to a developer how to use secrets. If you do it for your internal needs, to keep it simple, use secrets. Integration would be more preferable if you have multiple parameters for an integration.

    The ability for admin to store secrets: API keys, passwords, etc. Can be read from code.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...