Tag Archives: magento integration

Application Spotlight: Integrating to Magento


URL www.magentocommerce.com
Description Magento is the eCommerce software platform. Our evaluation is based on Magento Go
API Yes. http://www.magentocommerce.com/api/soap/introduction.html
Trial Version with API Access Yes.
Protocol SOAP v2 (This evaluation is based on Magento SOAP v2 API. Magento also support other protocols)
Data Format XML
Authentication Required username and apiKey login to get sessionId
 Update Query  Get  Delete 
 Customer Address
 Product Images
 Product Tier Price
 Product Links
 Credit Memo
 Shopping Cart
 Cart Product
 Cart Customer
 Cart Coupon
API Limits N/A
Sample Use Case Magento Customers > creates > Database Customer Table
Database Customer Table > updates > Magento Customers
Magento sales.Order > creates > Database Opportunity Table & OppLineItem Table
Database Product Table > creates > Magento catalog.Product
F2I 3.9/5

Magento Integration: Sales Order Synchronisation with Bundled Products

We talked about how to handle Configurable Product in my previous blog. Today, I will show you the difference of the Bundled Product.  In Magento, you can bundle a few Simple products together in Magento and sell it with a special price.
For example:
Bundle Product: My Computer Parts
Total Price: 450 
Bundle Items:
  1. NZXT Lexa Silver Aluminum ATX Mid-Tower Case (Normal Price: 150)
  2. AMD A64 X2 3800+ 2.0GHz OEM (Normal Price:  100)
  3. Western Digital – 1TB HD – 7200RPM (Normal Price:  300)
From the Magento API, you will receive the following data in a Sales Order:
<item xsi:type=”ns1:salesOrderItemEntity”>
                  <item_id xsi:type=”xsd:string”>1</item_id>
                  <order_id xsi:type=”xsd:string”>1</order_id>
                  <product_id xsi:type=”xsd:string”>165</product_id>
                  <product_type xsi:type=”xsd:string”>bundle</product_type>
                  <sku xsi:type=”xsd:string”>mycomputerparts</sku>
                  <name xsi:type=”xsd:string”>My Computer Parts</name>
                  <price xsi:type=”xsd:string”>450.0000</price>
<item xsi:type=”ns1:salesOrderItemEntity”>
                  <item_id xsi:type=”xsd:string”>2</item_id>
                  <order_id xsi:type=”xsd:string”>1</order_id>
                  <product_id xsi:type=”xsd:string”>139</product_id>
                  <product_type xsi:type=”xsd:string”>simple</product_type>
                  <sku xsi:type=”xsd:string”>nzxtlexa</sku>
                  <name xsi:type=”xsd:string”>NZXT Lexa Silver Aluminum ATX Mid-Tower Case (Default)</name>
                  <price xsi:type=”xsd:string”>150.0000</price>
<item xsi:type=”ns1:salesOrderItemEntity”>
                  <item_id xsi:type=”xsd:string”>3</item_id>
                  <order_id xsi:type=”xsd:string”>1</order_id>
                  <product_id xsi:type=”xsd:string”>148</product_id>
                  <product_type xsi:type=”xsd:string”>simple</product_type>
                  <sku xsi:type=”xsd:string”>amda64</sku>
                  <name xsi:type=”xsd:string”>AMD A64 X2 3800+ 2.0GHz OEM</name>
                  <price xsi:type=”xsd:string”>100.0000</price>
<item xsi:type=”ns1:salesOrderItemEntity”>
                  <item_id xsi:type=”xsd:string”>4</item_id>
                  <order_id xsi:type=”xsd:string”>1</order_id>
                  <product_id xsi:type=”xsd:string”>149</product_id>
                  <product_type xsi:type=”xsd:string”>simple</product_type>
                  <sku xsi:type=”xsd:string”>1tb7200</sku>
                  <name xsi:type=”xsd:string”>Western Digital – 1TB HD – 7200RPM</name>
                  <price xsi:type=”xsd:string”>300.0000</price>
While you are sychronising a Sales Order to another system, you can’t copy all the prices of each items. It will give you a wrong total amount (450 150 100 300 = 1000). To overcome this situation, your integration logic should directly take the price from the Bundle product and ignore all the other prices from the Bundle items.

Magento Integration: Sales Order Synchronisation with Configurable Products

Magento supports different product types. Each product type has its own characteristic from the API. It is important to understand them before building the integration.


Magento User can create Simple product from the Configurable product by choosing different options. For example, in our sample store, someone has purchased a medium size T-shirt (The Only Children: Paisley T-Shirt). The Sales Order will look like this:

<item xsi:type=”ns1:salesOrderItemEntity”>
<item_id xsi:type=”xsd:string”>14</item_id>

    <product_id xsi:type=”xsd:string”>123</product_id>
    <product_type xsi:type=”xsd:string”>configurable</product_type>
    <sku xsi:type=”xsd:string”>oc_med</sku>
<name xsi:type=”xsd:string”>The Only Children: Paisley T-Shirt</name>

    <price xsi:type=”xsd:string”>120.0000</price>

<item xsi:type=”ns1:salesOrderItemEntity”>
<item_id xsi:type=”xsd:string”>15</item_id>

    <product_id xsi:type=”xsd:string”>124</product_id>
    <product_type xsi:type=”xsd:string”>simple</product_type>
    <sku xsi:type=”xsd:string”>oc_med</sku>
<name xsi:type=”xsd:string”>The Only Children: Paisley T-Shirt</name>

    <price xsi:type=”xsd:string”>0.0000</price>


From the extracted data above, we can see that:
  • product_id : Each item will have a unique product_id. One represents the Configurable product and another one represents the simple product.
  • product_type  : Both items will have different product types.
  • price : The price will only appear in the Configurable (parent) item. The simple product will show 0 value.

Magento API integration – complex filter – multiple values

Integrating with Magento?
Here is a Magento API example of how to query with multiple values using the operator “in” (In the given array):
<filters xsi:type=”urn:filters”>
            <complex_filter xsi:type=”urn:complexFilterArray” soapenc:arrayType=”urn:complexFilter[]”>
Another key that supports multiple values is “nin” (Not in the given array), which is the opposite of “in” operator. The “in” operator matches the values with the given array while “nin” returns a result which does not contain the values specified.
Please note that if the operator is not recognised by Magento then by default “eq”(equal) will be used.
Hope you find that helpful.

Tips: Magento API – filter and complex filter

When you are querying records in Magento, you can use filter to narrow down the result.

The basic filter uses the EQUAL operator and AND operand. For example, you can query products with two basic filters: type=simple AND set=39


      <urn:catalogProductList soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>

         <sessionId xsi:type=”xsd:string”>c9f1ca71de1da4202c84bf90f6df51cf</sessionId>
         <filters xsi:type=”urn:filters”>
            <filter xsi:type=”urn:associativeArray” soapenc:arrayType=”urn:associativeEntity[]”>
         <storeView xsi:type=”xsd:string”></storeView>
Using the complex filter, you can perform a more sophisticated search. For example, you can query customers with two complex filters: store_id=0 AND created_at>2012-05-13 06:11:00
      <urn:customerCustomerList soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
         <sessionId xsi:type=”xsd:string”>c9f1ca71de1da4202c84bf90f6df51cf</sessionId>
         <filters xsi:type=”urn:filters”>

            <complex_filter xsi:type=”urn:complexFilterArray” soapenc:arrayType=”urn:complexFilter[]”>


<value>2012-05-13 06:11:00</value>
      </urn:customerCustomerList>The complex filter also uses the AND operand. However, you can specify your own operator. For example: eq (equals), neq (not equals), gt (greater than), lt (less than), etc.

Tips: Retrieving the Product Quantity from the Magento API

Getting the product stock quantity in Magento is a bit tricky as you can’t get it from catalog_product.info API call.

You need to use cataloginventory_stock_item.list API call. It has only one argument:
  • array products – list of products IDs or Skus
The array or products here means that you can request multiple product id in a request. Here’s a snippet of what the product quantity soap request looks like:

<sessionId xsi:type=”xsd:string”>59bc9730d567c9351e2507acb1d97bd0</sessionId>
<products xsi:type=”urn:ArrayOfString” soapenc:arrayType=”xsd:string[]”>


And the result return:
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>16</product_id>
<sku xsi:type=”xsd:string”>n2610</sku>
<qty xsi:type=”xsd:string”>996.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>17</product_id>
<sku xsi:type=”xsd:string”>bb8100</sku>
<qty xsi:type=”xsd:string”>797.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>18</product_id>
<sku xsi:type=”xsd:string”>sw810i</sku>
<qty xsi:type=”xsd:string”>989.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>

Magento Integration: Synchronise Product Data

In Magento, one SKU can have different product names. For example: If you have two different store views, you can have your product name in two different languages

  • English: Table
  • Spanish: Silla

To do this via the Magento Core API, you will need to:

  1. Create the product using the catalogProductCreate function (default values)
  2. Update the product in each store view using catalogProductUpdate function

Magento Integration: Access to web services

In order to access Magento web services API, you will need to do the following:

  1. Log in with a username and API key. This username is not the same as the username that you used to log in to the admin backend of the store. You will need to create an API user and role assigned to this user in Admin panel.
  2. Upon successful login, it would then return a session ID (security token). The session ID is mandatory in every API call request. Unlike other security tokens, there will be session timeout and this session ID would be expired automatically in a period of time. Once the session ID is expired, you will not be able to perform any API call request, and you will have to perform log in again to get a new session ID.

Magento only accepts the latest and only one session ID to be used in the API call. Therefore, if there are more than one user trying to access the API, it is a good practise to have only one session ID at a time and be shared among the users until this session ID is expired.

The following are the steps to setup a new API user from Magento’s backend admin.

Step 1:
Create an API user’s role under the admin panel, System->Web Services->Roles

Step 2:
Press “Add New Role” button to create a role for an API user.

Step 3:
Under “Role Info”, create a role’s name.

Step 4:
Under “Role Resources”, set permissions or restrictions for the user to access certain levels of data. Either select “All” or “Custom” for accessing the resources.

Step 5:
Create API user under the admin panel, System->Web Services->Users

Step 6:
Press “Add New User”.

Step 7:
Create an user account by filling up all the required field.

Note: Account must be set to “Active” in order for this user to access the API.

Step 8:
Select the user role for the user.

Finally, the API user is created.

Note: User can create one or more API user(s) and role(s).

Magento Integration : Customer Synchronisation

Magento has a different data model for customer. It’s more like a ‘contact’ centric system then an ‘account’ centric system. It treats all customer as an individual instead of a company.

If you are integrating Magento with Salesforce, perhaps you should consider the Person Account feature. It would be the good fit for the design.

If you really have to get the company information from Magento customer, you can get it from the address object. One Magento customer can have more than one addresses. Designing how the data synchronised between two different data set is crucial.

Feel free to contact us if you are interested to know more.

Magento Integration: Product Type

Magento supports a few product types. Each product type has different behavior. This is important when you design the product synchronisation process.

For example, if you are integrating Salesforce and Magento in the following scenario:

Magento Order > Creates > Salesforce Opportunity

If one of the order line items is a bundle product, you may get more than one line item returned from the API.

Order item from UI

XML data from API

The bundle product and all the associated items will be listed in the API. It is important to filter the list before you push it to Salesforce.