cancel
Showing results for 
Search instead for 
Did you mean: 

Magento SOAP api and product identifier.

Magento SOAP api and product identifier.

When requestion product information using a SOAP enveloppe you can specify the king of identifier (id or sku) you are using by adding the optional tag "<identifierType>?</identifierType>" .

 

This is not the case when calling the Inventory webservices!

 

So, when I have sent the following enveloppe:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
    <urn:catalogInventoryStockItemUpdateRequestParam>
        <sessionId>3dbc4a5e4f3a59b2e5f47fb00a35caaa</sessionId>
        <productId>47456</productId>
        <data>
            <qty>8.0</qty>
            <is_in_stock>1</is_in_stock>
       </data>
    </urn:catalogInventoryStockItemUpdateRequestParam>
</soapenv:Body>
</soapenv:Envelope>

 

Instead of updating the stock quantity of the product_id 47456, I was updating the product with the sku 47456.

By checking the api code, I noticed that Magento try a load by sku first and if it doesn't return an object it loads the product by id.

 

This is quite dangerous for shops using integer as SKU (like in the case of my client).

The optional tag "<identifierType>?</identifierType>"  should be integrated to any webservice that uses product_ids as a parameter.

 

 

 

2 REPLIES 2

Re: Magento SOAP api and product identifier.

What is the question exactly?

Magento Moderator since 2009
Keep Calm and Clear Cache!

Re: Magento SOAP api and product identifier.

This was more about pointing a API problem than asking for a solution.

 

The solution was for me to comment those lines everywhere in the API because I never use the SKU as an identifier:

 

//$idBySku = $product->getIdBySku($productId);
//$productId = $idBySku ? $idBySku : $productId;

 

The solution to make the API 100% safe should be to add everywhere the <identifierType> parameter when <productId> parameter is sent to the API. The automation of switching between SKU or ID is a source of mistake for anyone using the API.