Magento – MG2 Integration give error Unable to post data to consumer due to an unexpected error

apiintegrationmagento2setup-script

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>nolopetize@gmail.com</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

Best Answer

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.

Related Topic