An integration enables third-party services to call the Magento web APIs. The Magento APIs currently supports Accounting, Enterprise Resource Planning (ERP), Customer Relationship Management (CRM), Product Information Management (PIM), and marketing automation systems out of the box.
In this tutorial, I will present you the way to create an intergration in magento 2. Before you begin creating a module, make sure that you have a working installation of Magento 2.0, and the Magento System Requirements.
To create an integration, follow these general steps:
Table of Contents
To develop a module, you have to:
The module for an integration can be placed anywhere under the Magento root directory, but the recommended location is <magento_base_dir>/vendor/<vendor_name>/module-<module_name>
.
Also create etc
, etc/integration
, and Setup
 subdirectories under module-<module_name>
, as shown in the following example:
cd <magento_base_dir> mkdir -p vendor/<vendor_name>/module-<module_name>/etc/integration mkdir -p vendor/<vendor_name>/module-<module_name>/Setup
The etc/module.xml
file provides basic information about the module. Change directories to the etc directory and create the module.xml
file. You must specify values for the following attributes:
Attribute | Description |
name | A string that uniquely identifies the module. |
setup_version | The version of Magento the component uses |
The following example shows an example etc/module.xml
 file.
<?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="Vendor1_Module1" setup_version="2.0.0"> <sequence> <module name="Magento_Integration"/> </sequence> </module> </config>
Module Magento_Integration
 is added to “sequence†to be loaded first. It helps to avoid the issue, when a module with integration config loaded, that leads to a malfunction.
composer.json
 fileComposer is a dependency manager for PHP. You must create a composer.json
 file for your module so that Composer can install and update the libraries your module relies on. Place the composer.json
 file in the module-<module_name>
 directory.The following example demonstrates a minimal composer.json
 file.
registration.php
 fileThe registration.php
 registers the module with the Magento system. It must be placed in the module’s root directory.
<?php /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor1_Module1', __DIR__ );
Change directories to your Setup
 directory. Create a InstallData.php
 file that installs the integration configuration data into the Magento integration table.
The following sample is boilerplate and requires minor changes to make your integration work.
<?php namespace Vendor1\Module1\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']); } }
In the following line$this->integrationManager->processIntegrationConfig(['testIntegration']);
testIntegration
 must refer to your etc/integrations/config.xml
 file, and the integration name value must be the same.
Also, be sure to change the path after namespace
 for your vendor and module names.
Magento provides the Integration module, which simplifies the process of defining your integration. This module automatically performs functions such as:
To customize your module, you must create multiple XML files and read through others files to determine what resources existing Magento modules have access to.
The process for customizing your module includes 2 steps: Define the required resources, Pre-configure the integration.
The etc/integration/api.xml
 file defines which API resources the integration has access to.
To determine which resources an integration needs access to, review the permissions defined in each module’s etc/acl.xml
 file.
In the following example, the test integration requires access to the following resources in the Sales module:
<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>
Your module can optionally provide a configuration file config.xml
 so that the integration can be automatically pre-configured with default values. To enable this feature, create the config.xml
 file in the etc/integration
 directory.
If you pre-configure the integration, the values cannot be edited from the admin panel.
The file defines which API resources the integration has access to.
Element | Description |
integrations | Contains one or more integration definitions. |
integration name=”” | Defines an integration. The name  must be specified. |
An email to associate with this integration. | |
endpoint_url | Optional. The URL where OAuth credentials can be sent when using OAuth for token exchange. We strongly recommend using https:// . |
identity_link_url | Optional. The URL that redirects the user to link their 3rd party account with the Magento integration. |
Use the following steps to install your module:
bin/magento setup:upgrade
bin/magento setup:di:compile
Log in to Magento 2 and navigate to Settings > Extensions > Integrations. The integration should be displayed in the grid.
Before you can activate your integration in Magento 2, you must create two pages on your application to handle OAuth communications.
identity_link_url
 parameter must point to a page that can handle login requests.endpoint_url
 parameter (Callback URL in Admin) must be able to process OAuth token exchanges.When a merchant clicks the Activate button in Admin, a pop-up login page for the third-party application displays. Magento sends values for oauth_consumer_key
 and success_call_back
 parameters. The application must store the value foroauth_consumer_key
 tie it to the login ID. Use the success_call_back
 parameter to return control back to Magento.
The callback page must be able to perform the following tasks:
oauth_verifier
, the OAuth consumer key, and the OAuth consumer secret. The consumer key and secret are generated when the integration is created.POST /oauth/token/request
oauth_token
 and oauth_token_secret
.POST /oauth/token/access
oauth_token
 and oauth_token_secret
. These values will be different than those provided in the request token response.Authorization
 header in each call to Magento.Hopefully, you will get a general understanding about magento 2 intergration and know how to create an intergration in magento 2 through my sharing.
Related Blogposts You May be Interested In:
Magento 2 is an incredibly flexible and powerful eCommerce platform that can be tailored to…
Black Friday and Cyber Monday – BFCM 2024 are nearly around the corner, and it’s…
When it comes to e-Commerce platforms, undoubtedly Magento 2.0 grabs the spotlight. Magento might not…
The holiday shopping season is here, and there’s no better time to supercharge your Magento…
In today’s digital landscape, the rapid evolution of advanced web applications, particularly Progressive Web Apps…
As eCommerce booms, big data eCommerce will be all about providing insight into how to…