• By Bruma Pty. Ltd
  • contact
    DecEzy Knowledge Base

    Knowledge Base

    Magento API Overview

    Author admin acount on January 16, 2014 | Print | Bookmark

    Using Magento API with a .NET Application

    Firstly, this is not an ordinary article. This article is not about DecEzy, but rather about some of the underlying technology (using the Magento API from a .NET winforms application).

    If you are a DecEzy user looking for information about how to use/install DecEzy, then this article is not for you. If you are .NET developer looking to integrate your application with Magento, then this article is definitely for you. Please read on.

    Our Story

    When we first started looking into integrating with Magento via its API, we found Ez.Newsletter.MagentoApi library, which can be found here: https://code.google.com/p/csharlibformagexmlrpcapi/ . At first it seemed great - it took care of all the details with communicating with Magento, so we didn't have to worry about the nitty-gritty details. But as we started to use it, we found problems with it - it seemed to have errors, and was missing bits. We eventually came to the conclusion that it was out of date. The Magento API had progressed since this library was last maintained, and it was not of much use, unless we wanted to update it, which we didn't.

    So, leaving out a lot of detail, we found a better way, which is what we have documented here.

    Adding a Web Reference to your Application

    The first step is to add a web reference to your .NET application. Do this in visual studio, select "Add Web Reference" from either the project menu, or by right clicking on references in the solution explorer:

    In the "Add Web Reference" window that appears, put in the the address of your magento's installation SOAP v2 web service. This is the sites regular address, appended with "/api/v2_soap/?wsdl", as shown below. Then click on the "Go to" button.

    Visual studio will then query the website, and if it finds a web service there, display some details about it. When it does so, enter a name for the web service, and click on "Add Reference":

    You should now see the Magento API added to web references, as shown below:

    Now communicating with magento is just a simple matter of using the classes and methods created for you.

    Connecting to Magento

    Connecting to and disconnecting from Magento is done as shown below:

    Code Snippet
    1. // Connect first
    2. AppWide.MagentoAPI.MagentoService  magService = new AppWide.MagentoAPI.MagentoService();
    3. magService.Url = "http://yoursite.com/api/v2_soap/index";
    4. sessionId = magService.login("username", "password");
    5. // Do stuff here
    6. // Now disconnect
    7. magService.endSession(sessionId);

    The next step is to actually do stuff with Magento - read and write data to and from it. This will be in a later update of this article. Stay tuned.

    Was this article helpful?

    Yes No

    Category: Technical

    Last updated on January 16, 2014 with 713 views