Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
erezbenmoshe
Advocate I
Advocate I

Connecting to MAGENTO (eCommerce platform)

Hello,

 

Has anybody tried to connect to https://magento.com/?  If anyone did, I would appreciate some reference.

 

Thanks

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

I have not but I would assume that you would want to use the API: https://www.programmableweb.com/api/magento

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

11 REPLIES 11
jesurajsebamala
New Member

Connecting to a Magento eCommerce platform can be done using various methods depending on your needs, such as REST APIs, SOAP APIs, or direct database connections. Below, I'll guide you through connecting to Magento using REST APIs, which is the most common and recommended method for integration.

### Prerequisites
1. Magento installation (Magento 2 is used in this guide).
2. Admin access to Magento to create API credentials.
3. Python installed on your system.
4. `requests` library for Python (install via `pip install requests`).

### Steps to Connect to Magento Using REST APIs

#### 1. Create API Credentials
First, create an integration in Magento to obtain API credentials.

1. Log in to your Magento Admin Panel.
2. Go to `System` > `Integrations`.
3. Click `Add New Integration`.
4. Fill in the necessary details such as `Name`, `Email`, and `Callback URL`.
5. In the `API` section, set the `Resource Access` to `All` or customize it according to your needs.
6. Save the integration.
7. After saving, you'll see your new integration in the list. Click `Activate`.
8. Confirm the activation and note down the `Access Token` provided.

#### 2. Connect to Magento Using Python

With the API credentials ready, you can now use Python to interact with Magento.

**Install the `requests` library if you haven't already:**
```sh
pip install requests
```

**Sample Python Script to Connect and Fetch Data:**
```python
import requests

# Set your Magento instance URL and Access Token
base_url = 'https://your-magento-site.com/rest/V1'
access_token = 'your-access-token-here'

# Function to get headers with authorization
def get_headers():
return {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}

# Example: Get a list of products
def get_products():
endpoint = f'{base_url}/products'
response = requests.get(endpoint, headers=get_headers())
if response.status_code == 200:
return response.json()
else:
print(f'Error: {response.status_code}')
print(response.text)
return None

# Fetch products
products = get_products()
if products:
for product in products['items']:
print(f"ID: {product['id']}, Name: {product['name']}, Price: {product['price']}")
```

### Explanation
1. **Create API Credentials**: This step ensures that you have the required permissions to access Magento's data via APIs.
2. **Install Requests Library**: A popular HTTP library in Python for making requests to APIs.
3. **Set Base URL and Access Token**: Replace `'https://your-magento-site.com/rest/V1'` with your Magento instance URL and `'your-access-token-here'` with the Access Token you obtained.
4. **Get Headers**: This function returns the necessary headers including the Authorization Bearer token.
5. **Get Products Function**: This function makes a GET request to the `/products` endpoint to fetch product data.
6. **Fetch and Print Products**: Fetches the products and prints their ID, Name, and Price.

### Additional Examples
#### Create a New Product
Here’s how to create a new product using the REST API:

```python
import requests
import json

# Set your Magento instance URL and Access Token
base_url = 'https://your-magento-site.com/rest/V1'
access_token = 'your-access-token-here'

# Function to get headers with authorization
def get_headers():
return {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}

# Example: Create a new product
def create_product(product_data):
endpoint = f'{base_url}/products'
response = requests.post(endpoint, headers=get_headers(), data=json.dumps(product_data))
if response.status_code == 200:
return response.json()
else:
print(f'Error: {response.status_code}')
print(response.text)
return None

# Product data to create
new_product = {
"product": {
"sku": "new-sku",
"name": "New Product",
"attribute_set_id": 4,
"price": 100,
"status": 1,
"visibility": 4,
"type_id": "simple",
"weight": 1,
"extension_attributes": {},
"custom_attributes": []
}
}

# Create product
created_product = create_product(new_product)
if created_product:
print(f"Created Product ID: {created_product['id']}")
```

### Conclusion
Connecting to Magento using REST APIs is a powerful way to interact with your eCommerce platform programmatically. By following the steps outlined above, you can create integrations that fetch data, create new products, and perform other operations as needed.

Ensure you handle sensitive information like API tokens securely and follow best practices for error handling and logging in your production applications.

Read More
Adobe Commerce Development Services 
Pimcore Development Services
 
Magento Developers


Syndicate_Admin
Administrator
Administrator

I know that this issue has long been resolved, but you may be interested in this service. For connecting Power BI to Magento, I recommend checking out the InsightsReady extension available at https://insightsready.com. This tool specifically facilitates the integration of Magento with Power BI, making data analysis and reporting much more streamlined. It's worth exploring for your needs! I hope you find this useful)

alexkaranda
Frequent Visitor

just in case if somebody looking for ready and go solution

Free Power Bi APP for Magento. 

Doesn't require any extra extensions!

 

https://appsource.microsoft.com/en-us/product/power-bi/decimadigital.magento_powerbi

One can find help from Magento integration services.

Harry33
Helper I
Helper I

You can connect Magento and Power Bi via Skyvia — the no-coding integration solution. This integration isn't performed directly — Skyvia provides it through a database or cloud data warehouse with automatic schema creation. Then you can connect Power BI to this database or data warehouse easily.

kost
Frequent Visitor

For Magento there is an extension that integrates Magento store with Power BI: https://www.bimproject.net/en/products/extensions-for-magento/power-bi-integration.html

 

The integration is done with REST APIs and delivers data directly to Power BI Service. 

 

Another option is usage of OData API, which is also provided by Power BI Sales Cube extension for Magento:

https://www.bimproject.net/en/power-bi-sales-cube-package-for-magento.html

Greg_Deckler
Super User
Super User

I have not but I would assume that you would want to use the API: https://www.programmableweb.com/api/magento

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

This is very helpful.

Is there any tutorial specificially about how to use this API from PB? 

I am also looking for examples.

 

Thanks

Hi Eresbenmoshe

 

Did you every get this working?  I am trying to figure it out myself at the moment.

 

Mark B

I already did try this approach with connecting to Magento REST APIs. It takes significant efforts to get table by table being connected and data being extracted. It may put lot of presure on Magento (Adobe Commerce) server since API calls are not optimized for extraction of the whole history of data.

The best way to integrate Magento or Adobe Commerce with Power BI is to use Power BI Sales Cube extension from BIM. This solution delivers optimal data model into Power BI and keeps it updated by sending delta of the data. It is also very performant and can handle large datasets without taking performance of the system. It just that first load takes longer and every consequent data update happens in seconds.

As part of this extensions users may also add custom tables created based on Magento internal REST API endpoints, just to extend the core model. Such tables are taking longer to update and require manual data modeling, so they are used more to extend the model and not to replate it completelly.

Hi, 

 

No, I didn't.  If you find a way, I would love to hear.

 

Thanks,

Erez

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors