> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alumio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection guide

> Guide: connect Alumio to Magento 2 using bearer-token or request authentication.

### **Table Of Contents**

* Introduction
* Step 1: Create an HTTP Client
  * Step 1a: Setting the basics
  * Step 1b.1: Setting up authentication: Bearer token authentication
  * Step 1b.2: Setting up authentication: Request authentication
* Step 2: Interacting with the HTTP client
  * Step 2a: Creating an incoming configuration
  * Step 2b: Creating an outgoing configuration

### **Introduction**

Magento 2 is an e-commerce software solution that is used to sell products for both B2C and B2B customers all around the world.

When connecting with the Magento 2 API you are required to provide some form of authentication. This can either be:

* (static) API key authentication
* (dynamic) token-based authentication

Alumio offers you the ability to provide these authentications to a web service when making requests, this is done through *HTTP Authentications*.

For this guide, we will explain to you how to connect Alumio to Magento 2.

### **Step 1: Create an HTTP Client**

This section will explain how to set up an *HTTP Client* that can be used to consume one or more endpoints of Magento 2.

#### **Step 1a: Setting the basics**

To understand how to create an HTTP client you may follow the steps outlined within the following article: [Connecting to a REST API](https://forum.alumio.com/t/connecting-to-a-rest-api/216).

You will at least need the following three plugins:

* **Add base URI to requests**
* **Log requests**
  * Formatter: *Long*
* **Add content-type headers to requests**

Other plugins may be added as you see fit.

#### **Step 1b.1: Setting up authentication: Bearer token authentication**

The most simple way to authenticate to Magento 2 is through a bearer token, as this contains a static API token that only has to be set up once.

To achieve this way of authentication you need to follow these steps:

* Within Magento 2, navigate to *System -> Extensions -> Integrations*
* Click on the upper-right orange button: *Add New Integration*

<img src="https://mintcdn.com/alumio/V0k-1TTJzq5pKkjK/images/connectors/magento-2-guide-01.jpeg?fit=max&auto=format&n=V0k-1TTJzq5pKkjK&q=85&s=d2dd370bcea8e9f265ae6a24e231a024" alt="Magento 2 guide screenshot 1" width="2864" height="1360" data-path="images/connectors/magento-2-guide-01.jpeg" />

* Start by filling out the *name* for the integration, i.e. *Alumio*, and *password*
* Go to the API tab and assign all relevant APIs
* Hit *save*

<img src="https://mintcdn.com/alumio/V0k-1TTJzq5pKkjK/images/connectors/magento-2-guide-02.jpeg?fit=max&auto=format&n=V0k-1TTJzq5pKkjK&q=85&s=a5929b4a382231f0d1f5ef44abd9a3b0" alt="Magento 2 guide screenshot 2" width="2868" height="1316" data-path="images/connectors/magento-2-guide-02.jpeg" />

* Go back to the *Integrations* overview page hit *Activate*
* On the pop-up press *Allow*
* You will now be given 4 tokens. Take note of the *Access token* and hit *Done*

*<img src="https://mintcdn.com/alumio/V0k-1TTJzq5pKkjK/images/connectors/magento-2-guide-03.jpeg?fit=max&auto=format&n=V0k-1TTJzq5pKkjK&q=85&s=6a08805beb89ae132683b5770c2084a6" alt="Magento 2 guide screenshot 3" width="2598" height="736" data-path="images/connectors/magento-2-guide-03.jpeg" />*

* Within the HTTP client, hit *Add new HTTP Authentication*
* Select *Bearer token authentication*
* Paste the *Access token* within the *Token* field within Alumio
* Alternatively, you may set up a separate *HTTP Authentication* configuration to hold this information and use the reference here.

<img src="https://mintcdn.com/alumio/V0k-1TTJzq5pKkjK/images/connectors/magento-2-guide-04.png?fit=max&auto=format&n=V0k-1TTJzq5pKkjK&q=85&s=c3dca870595e398b55c06c1ce1d70072" alt="Magento 2 guide screenshot 4" width="1864" height="360" data-path="images/connectors/magento-2-guide-04.png" />

#### **Step 1b.2: Setting up authentication: Request authentication**

In case you do not want to work with a static API token, you may opt to go with the token-based authentication functionality offered by Magento 2. This requires you to first fire a request using user credentials which will return an access token that can be used in subsequent requests. Currently, the *Request authentication* method does not cache the token generated, so it is regenerated every time an API call is being done through the HTTP client.

* Within the HTTP client, hit *Add new HTTP Authentication*
* Select Request *authentication*
* The *Request URI* field should contain the URL to the authentication endpoint
* The *Request Method* needs to be *post* for Magento 2
* The *Request Parameters* should be a *object* and contain the *username* and *password* of the user you want to use to authenticate.
* *HTTP Client* should be *Default client*
  * A seperate *HTTP Client* may be needed when there is additional authentication required for the authentication endpoint configured within the *Request URI*
* The *Header* name we want to add to subsequent requests is *Authorization*
* The *Source* should be from the *Request body* as Magento 2 returns the generated authentication token within the body of the response
* The *Template* determines what value the header will be populated with. In our case this should be *Bearer &\{@\[0]}*.
  * *Bearer -* This part is static as it determines we want to authorize ourselves using a Bearer token (similarly to the bearer token authentication, but this uses a dynamic token opposed to a static one).
  * *&\{@\[0]} -* The *&\{}* part indicates a placeholder, or a variable, and indicates to Alumio we want to take data of the response of the authentication call. *@* indicates we want to take the entire response. Magento 2 returns a string that contains the token. Alumio interprets this as an array so we use *\[0]* to select this first and only item.

<img src="https://mintcdn.com/alumio/V0k-1TTJzq5pKkjK/images/connectors/magento-2-guide-05.png?fit=max&auto=format&n=V0k-1TTJzq5pKkjK&q=85&s=96580039f891670da4908c16482c49df" alt="Magento 2 guide screenshot 5" width="2100" height="2153" data-path="images/connectors/magento-2-guide-05.png" />

### **Step 2: Interacting with the HTTP client**

Now that you have set up the HTTP client, you can interact with it through an incoming or outgoing configuration. Incoming configurations allow you to read data from Magento 2, while an outgoing configuration will enable you to send data to a Magento 2.

#### **Step 2a: Creating an incoming configuration**

[Click here to review the general guide on incoming configurations in order to get familiar with their purpose.](https://forum.alumio.com/t/outgoing-in-alumio/175)

Using the HTTP subscriber: [Connecting to a REST API](https://forum.alumio.com/t/connecting-to-a-rest-api/216)

#### **Step 2b: Creating an outgoing configuration**

[Click here to review the general guide on outgoing configurations in order to get familiar with their purpose.](https://forum.alumio.com/t/outgoing-in-alumio/175)

Using the (Chain) HTTP publisher: [Connecting to a REST API](https://forum.alumio.com/t/connecting-to-a-rest-api/216)
