Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 3
Api & .Net
 
Peter Snows
Jr. Member
 
Total Posts:  12
Joined:  2008-07-16
 

iam able to register the web reference.
But I still haven’t figure it out how to get a product list.

In PHP you can do it like this.

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId $proxy->login('apiUser''apiKey');
 
$filters = array(
    
'sku' => array('like'=>'zol%')
);
$products $proxy->call($sessionId'product.list', array($filters));
var_dump($products);

How can I do the same in VB .NET ?
I dont’t think that VB supports arrays inside arrays.

Thanks,

Pedro

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jake99
Member
 
Total Posts:  32
Joined:  2008-10-30
 

Hello,

I am trying to push a product into the db using vb.net and webservices. I am able to get the product partially into the db but am having an issue with the attributes. I am currently serializing the array of attributes which is below, but I get an error when trying to call the product.create. If I leave the array empty data does populate the catalog_product_entity table. Any help would be appreciated.

Jake

vb.net Error: Message “No date part in ‘<’ found.”

attributes serialized
<?xml version="1.0" encoding="utf-16"?>
<Products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="prod">
<name>Test_Printer</name>
<short_description>test short description</short_description>
<description>Test Printer 580 - Long Description</description>
<price>129.99</price>
</Products>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Manoj.tripathi
Jr. Member
 
Total Posts:  2
Joined:  2009-03-06
 

Hi All,

I am trying to consume the Magento web services in C#.Net.

I followed the steps:
1. open the wsdl.xml in IE.
2. Copy all the contents & paste the contents into my.wsdl file.
3. Remove all the extra characters from my.wsdl file.  like ‘-’ , until the file open correctly in IE.
4.  C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ wsdl.exe my.wsdl
5. It will create MagentoService.cs as a result of step 4. This is the proxy file of web service.
6.  write code in visual studio 2008

using System;
using System.Xml;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MagentoService m = new MagentoService();
string login = m.login("apiUserName", “apiUserKey"); //It will return the session ID.

ArrayList newCustomer = new ArrayList();
newCustomer.Add("firstname");
newCustomer.Add("middlename" );
newCustomer.Add("lastname");
newCustomer.Add("suffix");
newCustomer.Add("email");
newCustomer.Add(MD5Con.EncodePassword("password"));
newCustomer.Add(0);
newCustomer.Add(0);

object custid;
custid = (object)m.call(login, “customer.create”, newCustomer );
XmlNode[] wtf = (XmlNode[])m.call(login, “customer.info”, custid);

}
}
public static class MD5Con
{
public static string EncodePassword(string originalPassword)
{
//Declarations
Byte[] originalBytes;
Byte[] encodedBytes;
MD5 md5;

//Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
md5 = new MD5CryptoServiceProvider();
originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
encodedBytes = md5.ComputeHash(originalBytes);

//Convert encoded bytes back to a ‘readable’ string
return BitConverter.ToString(encodedBytes);
}
}

Above code is working, but it is inserting balnk record.
I customer_entity table it is inserting balnk in email field.
I am guessing there is some error in object mapping.
Can any one tell how we can create the equivalent code as below, which will map correctly.

// Create new customer
$newCustomer = array(
‘firstname’ => ‘First’,
‘lastname’ => ‘Last’,
‘email’ => ‘test@example.com’,
‘password’ => ‘password’,
‘store_id’ => 0,
‘website_id’ => 0
);

$newCustomerId = $proxy->call($sessionId, ‘customer.create’, array($newCustomer));
This array is important , please tell the equivalent code for C#.

I will be thankful if any one can give the correct response. Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bilderbach
Jr. Member
 
Total Posts:  1
Joined:  2009-03-10
 

Anyone getting anywhere on this, having similar issues posting inventory updates from C#, tried using hashtables, collections and object arrays...nothing seems to pass properly!  I keep getting various errors generating XML no matter what approach I take:

System.InvalidOperationException: There was an error generating the XML document

 
Magento Community Magento Community
Magento Community
Magento Community
 
miliscent
Member
 
Avatar
Total Posts:  45
Joined:  2009-03-11
Pittsburgh, Pennsylvania USA
 

Yes, we are able to pass filter params using new object[] { “string”, 100001, myStruct } and also by creating structs to pass associative style arrays.  The objec[] array will allow you to mix types in it and also arrays in arrays, etc.

When the docs say params are optional, they are usually saying this : new object[] { “this param required”, “this one optional” } and not actually another parameter, just another item in the array.

Also keep in mind that even though you are only passing somethinng like an order id, it still needs wrapping in an array like this:

new object[] { 10000001 }

There is hope though!  We’ve built and entire .net object library with samples to all thes api’s objects and methods.  The best part is it’s totally free as we’ve released it under the MIT X11 license.  It includes samples to work with all objects and methods too.

You can read more about it and download it here:

.NET C# Object Library for Magento’s XML-RPC API

 
Magento Community Magento Community
Magento Community
Magento Community
 
Manoj.tripathi
Jr. Member
 
Total Posts:  2
Joined:  2009-03-06
 

Hi miliscent ,

Thanks for reply. It is realy helpful. I am going through xmlrpc approach.

I have done the same by using HttpSOAPRequest.

Please give your views & suggestions about the approach mentioned below:

protected void Button1_Click(object sender, EventArgs e)
{
string firstname = TextBox1.Text;
string lastname = TextBox2.Text;
string email = TextBox3.Text;
string password_hash = TextBox4.Text;
MagentoService m = new MagentoService();
string login = m.login("apiUserid", “123456");

StringBuilder SoapReq = new StringBuilder();
SoapReq.Append("<?xml version='" + "1.0" + "' encoding='" + "UTF-8" + "' ?>");
SoapReq.Append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=’” + “http://schemas.xmlsoap.org/soap/envelope/” + ”’ xmlns:ns1=’” + “urn:Magento” + ”’ xmlns:xsd=’” + “http://www.w3.org/2001/XMLSchema” + ”’ xmlns:xsi=’” + “http://www.w3.org/2001/XMLSchema-instance” + ”’ xmlns:ns2=’” + “http://xml.apache.org/xml-soap” + ”’ xmlns:SOAP-ENC=’” + “http://schemas.xmlsoap.org/soap/encoding/” + ”’ SOAP-ENV:encodingStyle=’” + “http://schemas.xmlsoap.org/soap/encoding/” + “‘> “);
SoapReq.Append("<SOAP-ENV:Body>");
SoapReq.Append("<ns1:call>");
SoapReq.Append("<sessionId xsi:type=’” + “xsd:string” + “‘>");
SoapReq.Append(login);
SoapReq.Append("</sessionId>");
SoapReq.Append("<resourcePath xsi:type=’” + “xsd:string” + “‘>customer.create</resourcePath>");
SoapReq.Append("<args SOAP-ENC:arrayType=’” + “ns2:Map[1]” + ”’ xsi:type=’” + “SOAP-ENC:Array” + “‘>");
SoapReq.Append("<item xsi:type=’” + “ns2:Map” + “‘>");

SoapReq.Append("<item> <key xsi:type=’” + “xsd:string” + “‘>firstname</key>");
SoapReq.Append("<value xsi:type=’” + “xsd:string” + “‘>");
SoapReq.Append(firstname);
SoapReq.Append("</value> </item>");

SoapReq.Append("<item> <key xsi:type=’” + “xsd:string” + “‘>lastname</key>");
SoapReq.Append("<value xsi:type=’” + “xsd:string” + “‘>");
SoapReq.Append(lastname);
SoapReq.Append("</value> </item>");

SoapReq.Append("<item> <key xsi:type=’” + “xsd:string” + “‘>email</key>");
SoapReq.Append("<value xsi:type=’” + “xsd:string” + “‘>");
SoapReq.Append(email);
SoapReq.Append("</value> </item>");

SoapReq.Append("<item> <key xsi:type=’” + “xsd:string” + “‘>password_hash</key>");
SoapReq.Append("<value xsi:type=’” + “xsd:string” + “‘>");
SoapReq.Append(password_hash);
SoapReq.Append("</value> </item>");
SoapReq.Append("</item> </args></ns1:call> </SOAP-ENV:Body></SOAP-ENV:Envelope> “);

StringReader sr = new StringReader(SoapReq.ToString());
HttpSOAPRequest(sr);
Label1.Text = “Customer Successfully Added”;
}
}
void HttpSOAPRequest(StringReader xmlfile)
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlfile);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/magento/index.php/api/soap/index/");
req.Headers.Add("SOAPAction", “\"\"");
req.ContentType = “text/xml;charset=\"utf-8\"”;
req.Accept = “text/xml”;
req.Method = “POST”;

Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();

WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
miliscent
Member
 
Avatar
Total Posts:  45
Joined:  2009-03-11
Pittsburgh, Pennsylvania USA
 

My suggestion to you, if you really want to use SOAP, is to follow the PHP samples in the Wiki.  Find the sample for what you want to do and get it working in your test env.

If it’s local env you are running from, use Fiddler2 to view the request/response on your local machine.  If not, then dump the soap from the PHP soap proxy client (I don’t know method to do it).  This way you see working soap calls exactly as they are and you can mimic them as your doing above.

But honestly, I’d download the libary we published.  All the source is included there.  Working with the objects is sooo much easier especially with intellisense.  Plus we have working samples in there for every single object/method.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hey miliscent,

thanks for your contribution. I had been butting my head against the wall all day yesterday trying to get this to work.
Your detailed examples are just what i needed and now have a vb version based on the product.list.

excellent work

brendan

 
Magento Community Magento Community
Magento Community
Magento Community
 
miliscent
Member
 
Avatar
Total Posts:  45
Joined:  2009-03-11
Pittsburgh, Pennsylvania USA
 

Thank you for the kind words.  We too slammed our heads off the desk while working with the api in .net.  We only really needed to list the orders.  But once we figured that out, we just went ahead and built the whole shebang and published the source because there was a great need for it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hi miliscent,

i just have a question you might be able to help me with. Im pretty scetchy on vb, but i would like to build a datatable based on the returned results from the API call to lets say product.list

Currently im hard coding the field names. But that is kinda dumb!.

With dt
            
.Columns.Add("Name"GetType(Object))
            .
Columns.Add("Sku"GetType(Object))
            .
Columns.Add("Set"GetType(Object))
            .
Columns.Add("category_ids"GetType(Object))
            .
Columns.Add("color"GetType(Object))
            .
Columns.Add("z_product_id"GetType(Object))
            .
Columns.Add("type"GetType(Object))
        
End With

What i would like to do is just iterate through the product class and pull the names of each property and use these in a loop.
any chance you could sketch up a c# example of this. Ive tried looking round for some sort of example, but nothing.

thanks
Brendan

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

ok, i found a solution

Dim p As Type GetType(clsMagentoProduct)
        
Dim properties From props In p.GetProperties Select props

        
For Each prop In properties
            MessageBox
.Show(prop.Name)
        
Next
 
Magento Community Magento Community
Magento Community
Magento Community
 
miliscent
Member
 
Avatar
Total Posts:  45
Joined:  2009-03-11
Pittsburgh, Pennsylvania USA
 

Glad you got it working.

In the samples there is a Utils class which has the following method:

public static void StructDiscovery(object[] bar)

This class will loop through all the property values returned directly from the xml-rpc api call and display them.

How we built each class was to setup the interface and static methods to return “object[]” and then passed the results to this class to view them.

We then used this method to write the private member variables and public properties to a local file:

object[] myProducts MagentoApi.Product.List(apiUrlsessionId, new object[] { filterOn });

Utils.ClassPropertyBuilder(myProducts);

From which we then copied and pasted into the classes as we built them.  From there were changed the return type of the interface and static class to the type ie. from object[] to Product[] and voila, classes were born.  The only snags we hit with this method were that some properties were arrays but you you can see that in the StructDiscovery method.

Hope that helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

hey thanks,

im starting to get to grips with it. one thing i cannot do though is just get a product.list without passing parameters.

for example i can see you have the following method

// method list products
        public static Product[] List(string apiUrlstring sessionId)
        
{
            IProduct prox 
= (IProduct)XmlRpcProxyGen.Create(typeof(IProduct));
            
prox.Url apiUrl;
            return 
prox.List(sessionId_catalog_product_list);
        
}

but when i try and use this i continually geta time-out error.

I can however use the other method fine which i have to pass paramters. But im really just after a straight list
Just wondering if you got this to work on your system?

cheers
Brendan

 
Magento Community Magento Community
Magento Community
Magento Community
 
miliscent
Member
 
Avatar
Total Posts:  45
Joined:  2009-03-11
Pittsburgh, Pennsylvania USA
 

You can pass an empty object like this:

Product[] myProducts MagentoApi.Product.List(apiUrlsessionId, new object[] { });

That works fine on our demo store and returns the full list of products.  Does it work for you?

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendanb
Mentor
 
Total Posts:  1093
Joined:  2008-07-16
London, United Kingdom
 

ta.

i tried what you said but it kills my server

Server returned a fault exception: [1] SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

banging my head against wall now grin

brendan

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 3