Close [x]

Create an integration

Edit this page on GitHub

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.

Implementing an integration requires little knowledge of PHP or Magento internal processes. However, you will need a working knowledge of

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:

  1. Create a module with the minimal structure and configuration.
  2. Add files specific to the integration.
  3. Install the module.
  4. Check the integration.

Create a skeletal module

To develop a module, you must:

  1. Create the module file structure. 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 and integration subdirectories under module-<module_name>, as shown in the following example:

     cd <magento_base_dir>
     mkdir vendor/<vendor_name>/module-<module_name>
     cd vendor/<vendor_name>/module-<module_name>
     mkdir etc
     mkdir integration
    

    For more detailed information, see Create the module file structure.

  2. Define your module configuration file. 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:

    AttributeDescription
    name A string that uniquely identifies the module.
    setup_version The version of Magento the component uses

    The following example shows an example 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">
           </module>
         </config>
    
  3. Add your module鈥檚 composer.json file. Composer 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.

       {
          "name": "Vendor1_Module1",
          "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": {
                "Vendor1\\Module1\\": ""
             }
          }
       }
     

    For more information, see Create a component.

  4. Create a registration.php file The registration.php registers the module with the Magento system. It must be placed in the module鈥檚 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__
         );
       

Create integration files

Magento provides the Integration module, which simplifies the process of defining your integration. This module automatically performs functions such as:

  • Managing the third-party account that connects to Magento.
  • Maintaining OAuth authorizations and user data.
  • Managing security tokens and requests.

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

Define the required resources

The 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鈥檚 etc/acl.xml file.

In the following example, the test integration requires access to the following resources in the Sales module:

<integrations>
    <integration name="Test Integration">
        <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>
    <integration name="Test Integration2">
        <resources>
            <resource name="Magento_Sales::sales" />
            <resource name="Magento_Sales::sales_operation" />
            <resource name="Magento_Sales::transactions" />
        </resources>
    </integration>
</integrations>

Pre-configure the integration

Your module can optionally provide a configuration file so that the integration can be automatically pre-configured with default values. To enable this feature, create the config.xml file in the integration directory.

If you pre-configure the integration, the values cannot be edited from the admin panel.

<integrations>
   <integration name="TestIntegration1">
       <email></email>
       <endpoint_url></endpoint_url>
       <identity_link_url></identity_link_url>
   </integration>
</integrations>
Element Description
integrations Contains one or more integration definitions.
integration name="" Defines an integration. The name must be specified.
email Optional. 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://.

See [OAuth-based authentication](../../get-started/authentication/gs-authentication-oauth.html) for details.

identity_link_url Optional. The URL that redirects the user to link their 3rd party account with the Magento integration.

Install your module

Use the following steps to install your module:

  1. Change directories to the var directory and remove its contents.

      cd /
      rm -rf var/* 
    
    
  2. Run the following command to update the Magento database schema and data.

    bin/magento setup:upgrade

  3. Run the following command to generate the new code.

    bin/magento setup:di:compile

Check your integration

Log in to Magento and navigate to Settings > Extensions > Integrations. The integration should be displayed in the grid.

Related Topics