I am trying to fetch all the orders and customer from Magento 2 to my python based application. But I am not able to get any API to use in Python.

Anyone who has used Magento 2 SOAP API in python, please let me know.

1 Answer 1


Certainly! Using Magento 2's SOAP API from Python can be done using the zeep library, which is a SOAP client for Python. Below is a step-by-step guide to fetch all the orders and customers from Magento 2 to your Python-based application using the SOAP API:


  1. Install the zeep library using pip:
pip install zeep
  1. Ensure that you have set up API access in your Magento 2 instance and have the API key.


  1. Setting up a SOAP client:
from zeep import Client

WSDL_URL = "http://YOUR_MAGENTO_DOMAIN/soap/default?wsdl&services=integrationAdminTokenServiceV1"
client = Client(WSDL_URL)
  1. Retrieve the API Token: Replace YOUR_USERNAME and YOUR_PASSWORD with your API credentials from Magento.
credentials = {
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD"
token = client.service.integrationAdminTokenServiceV1CreateAdminAccessToken(**credentials)
  1. Fetch Customers: Now, create a new client for the customerCustomerRepositoryV1 service and fetch the customers.
CUSTOMER_WSDL_URL = "http://YOUR_MAGENTO_DOMAIN/soap/default?wsdl&services=customerCustomerRepositoryV1"
customer_client = Client(CUSTOMER_WSDL_URL)

# Set the required headers for the session
session_headers = {
    "Authorization": f"Bearer {token}"

# Fetch customers
customers = customer_client.service.customerCustomerRepositoryV1GetList()

  1. Fetch Orders: Similarly, create a client for the salesOrderRepositoryV1 service and fetch the orders.
ORDER_WSDL_URL = "http://YOUR_MAGENTO_DOMAIN/soap/default?wsdl&services=salesOrderRepositoryV1"
order_client = Client(ORDER_WSDL_URL)

# Set the required headers for the session

# Fetch orders
orders = order_client.service.salesOrderRepositoryV1GetList()


Note: Make sure to replace YOUR_MAGENTO_DOMAIN, YOUR_USERNAME, and YOUR_PASSWORD with appropriate values. Also, handle potential exceptions and add error checking as needed.

This should help you get started with using the Magento 2 SOAP API from Python. Depending on your specific requirements, you might need to adjust the above code or use other available SOAP services provided by Magento 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.