2

I'm follow the http://devdocs.magento.com/guides/v2.0/howdoi/webapi/integration.html and i have an error when i try do activates the integrator.

[2017-06-20 05:22:08] main.CRITICAL: Exception: Notice: Undefined index: TestIntegration in /srv/www/vendor/magento/module-integration/Model/Plugin/Integration.php on line 121 in /srv/www/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 /srv/www/vendor/magento/module-integration/Model/Plugin/Integration.php(121): Magento\Framework\App\ErrorHandler->handler(8, 'Undefined index...', '/srv/www/vendor...', 121, Array)
#1 /srv/www/vendor/magento/module-integration/Model/Plugin/Integration.php(101): Magento\Integration\Model\Plugin\Integration->_addAllowedResources(Object(Magento\Integration\Model\Integration))
#2 /srv/www/vendor/magento/framework/Interception/Interceptor.php(152): Magento\Integration\Model\Plugin\Integration->afterGet(Object(Magento\Integration\Model\IntegrationService\Interceptor), Object(Magento\Integration\Model\Integration))
#3 /srv/www/var/generation/Magento/Integration/Model/IntegrationService/Interceptor.php(65): Magento\Integration\Model\IntegrationService\Interceptor->___callPlugins('get', Array, Array)
#4 /srv/www/vendor/magento/module-integration/Controller/Adminhtml/Integration/PermissionsDialog.php(23): Magento\Integration\Model\IntegrationService\Interceptor->get(2)
#5 /srv/www/vendor/magento/framework/App/Action/Action.php(102): Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog->execute()
#6 /srv/www/vendor/magento/module-backend/App/AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#7 /srv/www/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#8 /srv/www/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor->___callParent('dispatch', Array)
#9 /srv/www/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Integra...', 'dispatch', Object(Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor), Array, 'adminAuthentica...')
#10 /srv/www/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#11 /srv/www/vendor/magento/framework/Interception/Chain/Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#12 /srv/www/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Integra...', 'dispatch', Object(Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor), Array, 'adminMassaction...')
#13 /srv/www/vendor/magento/module-backend/App/Action/Plugin/MassactionKey.php(33): Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 /srv/www/vendor/magento/framework/Interception/Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 /srv/www/var/generation/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog/Interceptor.php(26): Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor->___callPlugins('dispatch', Array, Array)
#16 /srv/www/vendor/magento/framework/App/FrontController.php(55): Magento\Integration\Controller\Adminhtml\Integration\PermissionsDialog\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#17 /srv/www/vendor/magento/framework/Interception/Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#18 /srv/www/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#19 /srv/www/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#20 /srv/www/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#21 /srv/www/vendor/magento/framework/Interception/Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#22 /srv/www/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#23 /srv/www/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#24 /srv/www/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#25 /srv/www/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#26 {main} [] []

My files:

etc/module.xml

<?xml version="1.0"?>
<!--
   /**
   * Copyright © 2015 Magento. All rights reserved.
   * See COPYING.txt for license details.
   */
   -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Sc_IntegrationAPI" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Integration"/>
        </sequence>
    </module>
</config>

etc/integrations/api.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <integrations>
        <integration name="testIntegration">
            <resources>
                <!-- To grant permission to Magento_Log::online, its parent Magento_Customer::customer needs to be declared as well-->
                <resource name="Magento_Customer::customer"/>
                <resource name="Magento_Log::online"/>
                <!-- To grant permission to Magento_Sales::reorder, all its parent resources need to be declared-->
                <resource name="Magento_Sales::sales"/>
                <resource name="Magento_Sales::sales_operation"/>
                <resource name="Magento_Sales::sales_order"/>
                <resource name="Magento_Sales::actions"/>
                <resource name="Magento_Sales::reorder"/>
            </resources>
        </integration>
    </integrations>
</config>

etc/integrations/config.xml

<?xml version="1.0"?>
<integrations>
    <integration name="TestIntegration">
        <email>[email protected]</email>
        <endpoint_url>http://default.sc.local/oauth.php</endpoint_url>
        <identity_link_url>http://default.sc.local/oauth.php</identity_link_url>
    </integration>
</integrations>

etc/Setup/InstallData.php

<?php
 namespace Sc\IntegrationAPI\Setup;

 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;
 use Magento\Integration\Model\ConfigBasedIntegrationManager;
 use Magento\Framework\Setup\InstallDataInterface;

 class InstallData implements InstallDataInterface
 {
     /**
      * @var ConfigBasedIntegrationManager
      */


     private $integrationManager;

     /**
      * @param ConfigBasedIntegrationManager $integrationManager
      */

     public function __construct(ConfigBasedIntegrationManager $integrationManager)
     {
         $this->integrationManager = $integrationManager;
     }

     /**
      * {@inheritdoc}
      */

     public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
     {
         $this->integrationManager->processIntegrationConfig(['testIntegration']);
     }
 }

Module/composer.json

{
  "name": "Sc_IntegrationAPI",
  "description": "create integration from config",
  "require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/framework": "2.0.0",
    "magento/module-integration": "2.0.0"
  },
  "type": "magento2-module",
  "version": "1.0",
  "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Sc\\IntegrationAPI\\": ""
    }
  }
}

Module/registration.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Sc_IntegrationAPI',
    __DIR__
);

EDIT: I followed answers below, and i have another error:

Unable to post data to consumer due to an unexpected error

What is it? thanks

1
  • When you get error Unable to post data to consumer due to an unexpected error the exception is not printed by default. Please, check your exception.log. Commented Jun 20, 2017 at 13:19

2 Answers 2

0

Please check our xml files. In your config.xml file, integration name is "TestIntegration" and in api.xml file, integration name is "iestIntegration" . Please firstly resolve this. If you are still facing issue. Please let me know.

3
  • yes, still the same error. Commented Jun 20, 2017 at 5:55
  • Please delete all static files and flush the cache. Commented Jun 20, 2017 at 6:01
  • I did this and it continues with the same error when I try to activate the Integrator in ""System > Integrations"" Commented Jun 20, 2017 at 6:21
0

I tested it on my dev-server and found the issue: the path etc/integrations/ should be etc/integration/ (without s at the end). At this point first error is gone, but another one is thrown:

[Magento\Framework\Exception\LocalizedException]
Invalid Document
Element 'config': No matching global declaration available for the validation root. Line: 2

The problem is in the etc/integration/api.xml config. It should be:

<?xml version="1.0"?>
<integrations>
    <integration name="TestIntegration">
        <resources>
            <!-- To grant permission to Magento_Log::online, its parent Magento_Customer::customer needs to be declared as well-->
            <resource name="Magento_Customer::customer"/>
            <resource name="Magento_Log::online"/>
            <!-- To grant permission to Magento_Sales::reorder, all its parent resources need to be declared-->
            <resource name="Magento_Sales::sales"/>
            <resource name="Magento_Sales::sales_operation"/>
            <resource name="Magento_Sales::sales_order"/>
            <resource name="Magento_Sales::actions"/>
            <resource name="Magento_Sales::reorder"/>
        </resources>
    </integration>
</integrations>

Without <config> node, as it declared in the .xsd file:

magento/module-integration/etc/integration/api.xsd

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Schema for API integration configuration.
 *
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
 @deprecated
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="integrations" type="integrationsType"/>
    <xs:complexType name="integrationsType">
        <xs:sequence>
            <xs:element name="integration" type="integrationType" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="integrationType">
        <xs:sequence>
            <xs:element name="resources" type="resourcesType"/>
        </xs:sequence>
        <xs:attribute name="name" type="integrationNameType" use="required"/>
    </xs:complexType>
    <xs:complexType name="resourcesType">
        <xs:sequence>
            <xs:element name="resource" type="resourceType" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="resourceType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="name" type="resourceNameType" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:simpleType name="resourceNameType">
        <xs:restriction base="xs:string">
            <xs:pattern value=".+_.+::.+"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="integrationNameType">
        <xs:restriction base="xs:string">
            <xs:minLength value="2"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
4
  • I tried with these changes, but I still can not activate the integrator and the error remains the same as exception.log. I will try on a new installation of magento2. Commented Jun 20, 2017 at 8:45
  • @MatheusSilvaItep Try to remove the integration and reinstall the module Commented Jun 20, 2017 at 8:49
  • ok, i almost can activate now. Give me another error: Unable to post data to consumer due to an unexpected error Commented Jun 20, 2017 at 11:59
  • @MatheusSilvaItep update your question with corresponding error from log. Commented Jun 20, 2017 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.