I am new to SOAP Web Service API's and Magento. Can someone show me an example of SOAP API request to return information about a product?
Magento – Examples of Magento SOAP API
soapsoap-api-v2
Related Solutions
Unfortunately it isn't possible out of the box. You are right, filters are only used to filter attributes and there is no "limit" parameter
Arguments:
Type | Name | Description string | sessionId | Session ID array | filters | Array of filters by attributes (optional) string | storeView | Store view ID or code (optional)
Source: http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.list.html
Looking at the source code of Mage_Catalog_Model_Product_Api
confirms it:
/**
* Retrieve list of products with basic info (id, sku, type, set, name)
*
* @param null|object|array $filters
* @param string|int $store
* @return array
*/
public function items($filters = null, $store = null)
{
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter($this->_getStoreId($store))
->addAttributeToSelect('name');
/** @var $apiHelper Mage_Api_Helper_Data */
$apiHelper = Mage::helper('api');
$filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
try {
foreach ($filters as $field => $value) {
$collection->addFieldToFilter($field, $value);
}
} catch (Mage_Core_Exception $e) {
$this->_fault('filters_invalid', $e->getMessage());
}
$result = array();
foreach ($collection as $product) {
$result[] = array(
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'category_ids' => $product->getCategoryIds(),
'website_ids' => $product->getWebsiteIds()
);
}
return $result;
}
The collection gets filtered by store and by attributes and that's it. No way to further manipulate it. What you'd need to do is write an own API model that extends this class and adds its own method itemsWithLimit()
with an additional parameter.
Update by request
if using the REST API with OAuth is an option, you actually can provide a limit:
Additional Information
You can define the limit of items returned in the response by passing the limit parameter. By default, 10 items are returned and the maximum number is 100 items. You can also define the page number by passing the page parameter. Example:
http://magentohost/api/rest/products?page=2&limit=20
Authorization header will be required for Admin and Customer user types. The following parameters must be provided in the Authorization header for the call:
- oauth_consumer_key - the Consumer Key value provided after the registration of the application.
- oauth_nonce - a random value, uniquely generated by the application.
- oauth_signature_method - name of the signature method used to sign the request. Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.
- oauth_signature - a generated value (signature).
- oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT.
- oauth_token - the oauth_token value (Request Token).
- oauth_version - OAuth version.
Source: http://www.magentocommerce.com/api/rest/introduction.html#RESTAPIIntroduction-Products
I was able to make requests to Magento 2 web API using the following example in 2014 (before 2.0 release), but it should work now as well.
To run it, follow the steps:
- Open Visual Studio C# 2010 Express
- Create new console application project
- In the project tree click on the project root to view context menu and select "Add Service Reference"
- Set address to
http://<magento.host>/soap/default?wsdl&services=customerCustomerAccountServiceV1
namespace toMagentoService
- Add example below to your project and update Access token field with actual value
- Run the program, console will be opened and simple attribute values are displayed
C# console application example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.MagentoService;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace ConsoleApplication1
{
class Program
{
const string accessToken = "9b8cpqlvrberc51o02nccmg82yyechxe";
static void Main(string[] args)
{
customerCustomerAccountServiceV1PortTypeClient customerApi = new customerCustomerAccountServiceV1PortTypeClient();
CustomerCustomerAccountServiceV1GetCustomerRequest request = new CustomerCustomerAccountServiceV1GetCustomerRequest();
request.customerId = 1;
CustomerCustomerAccountServiceV1GetCustomerResponse response;
try
{
/** Set authorization headers and sent a request */
using (OperationContextScope scope = new OperationContextScope(customerApi.InnerChannel))
{
var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Bearer " + accessToken;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
response = customerApi.customerCustomerAccountServiceV1GetCustomer(request);
}
CustomerV1DataCustomer customerData = response.result;
Console.Out.WriteLine("Customer email is: {0}.", customerData.email);
Console.Out.WriteLine("Custom attributes:", customerData.email);
foreach (FrameworkDataEavAttributeValue attribute in customerData.customAttributes)
{
/** Cast object of generic type to its real type */
System.Xml.XmlNode[] value = (System.Xml.XmlNode[])attribute.value;
Console.WriteLine("{0}: {1}", attribute.attributeCode, value[0].Value);
}
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
}
Console.In.Read();
}
}
}
This example uses Service reference (not Webservice), but still might be helpful to understand how to pass authentication headers.
Best Answer
I have a magento 1.9.x website and I have been using Soap WebService APIs for an internally developed Android Application for Order and Delivery Management.
To be able to use Soap WebServices, I followed the following steps:
Downloaded SoapUI
Installed SaopUI
Created a new project and provided "Initial WSDL" value as -
It exposed all the Soap bindings from my website
To use any webservice, login call is required to get the session id.
Login request would look like the content at