C# magento soap v2 api

Last modified by AndyP on Sat, September 24, 2011 00:34
Source|Old Revisions  

C# magento soap v2 api

If you’re like me you’ve been tasked with integrating the magento online system with legacy order fullfillment and accounting software in the back office. This guide serves to help anyone looking to use visual studio 2008 to program a c# application for ushering data in and out of magento. This guide is meant for version 1.3.2.3 though it may work with other versions. It should also be noted that I am using the .net framework version 3.5 though i’m not sure that’s relevant.

Making a connection

The first thing you need to do is log into magento and create a user and give him/her permission to query the api. System→Web Services

remember you api key because you will use it in the following steps.

Open up visual studio and create a new project. Mine was windows forms based. Under solution explorer right click and choose Add Service Reference when the dialog comes up click advanced. Next click Add Web Reference enter in the path to your wsdl file. and example would be

http://www.exampledomain.com/shop/index.php/api/v2_soap/?wsdl

click Go

You should now see “MagentoService” Description with a bunch of methods underneath.

set the web reference name in this case it would be com.exampledomain.www

Click Add Reference

You should now have a reference in the solution explorer. In order to use this in you project you simple need to put a

using com.exampledomain.com

You will then have access to the MagentoService object. This will be your primary object for interacting with magento. The following code serves to illustrate how you would use the MagentoService class.


           MagentoService mservice = new MagentoService();
           String mlogin = mservice.login("YOUR_USERNAME", "YOUR_API_KEY");
       
         Debug.WriteLine(mlogin);
          filters mf = new filters();
           complexFilter[] cpf = new complexFilter[1];
           complexFilter mcpf = new complexFilter();
           mcpf.key = "increment_id";
           associativeEntity mas = new associativeEntity();
           mas.key = "gt";
           mas.value = "1008001";
           mcpf.value = mas;
           cpf[0] = mcpf;
           mf.complex_filter = cpf;
          salesOrderEntity[] soe = mservice.salesOrderList(mlogin, mf);
          if (soe.Length > 0)
          {
 
              foreach (salesOrderEntity msoe in soe)
              {
                  try
                  {
                      Debug.WriteLine("" + msoe.billing_firstname + " " + msoe.subtotal);
                  }
                  catch (Exception merror)
                  {
                      MessageBox.Show("" + msoe.order_id + ""+merror.ToString());
                  }
              }
          }

—-

This code gets you all of the orders that are greater than a specified ordernumber and then iterates through each printing the billing firstname and the subtotal to the debugger.

The rest is up to you.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs