Forum Discussion
Connecting to MAGENTO (eCommerce platform)
Hello,
Has anybody tried to connect to https://magento.com/? If anyone did, I would appreciate some reference.
Thanks
I have not but I would assume that you would want to use the API: https://www.programmableweb.com/api/magento
10 Replies
- Greg_DecklerCommunity Champion
I have not but I would assume that you would want to use the API: https://www.programmableweb.com/api/magento
- erezbenmosheAdvocate I
This is very helpful.
Is there any tutorial specificially about how to use this API from PB?
I am also looking for examples.
Thanks
- WinedirectNew Member
Hi Eresbenmoshe
Did you every get this working? I am trying to figure it out myself at the moment.
Mark B
- kostFrequent 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
- alexkarandaFrequent 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
- zdjfskNew Member
One can find help from Magento hosting.
- Syndicate_AdminAdministrator
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)
- jesurajsebamalaNew 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