I have never used WebAPI at this point but as I understand it's just "another" way of providing webservices. In the following example I'm trying to add a product to my basket using the high level API.
Then you can call your service at /umbraco/basketapi/AddToBasket with AJAX. This is actually first time looking into WebApi but it seems quite easy to pass objects from AJAX. Try to take a look at this:
Yes you need to reference the assemblies you want to use.
I personally reference all uCommerce assemblies from my own assemblies if they're need in there. Otherwise if you have Resharper it tempts to take assemblies directly from bin folder in website (and that can be annoying if you're working on a team).
How to reference UCommerce.API in a custom UmbracoApiController
Hi,
I want to use the Web API / jQuery.Ajax to get product variants, add to cart etc
I've created a Controller inheriting UmbracoApiController, and placed the controller in the Controllers directory.
How do I use the UCommerce.API from within my controller? I want to pass in Product objects etc
Thanks.
Can anyone help out with this one?
Thanks.
Hi David,
I have never used WebAPI at this point but as I understand it's just "another" way of providing webservices. In the following example I'm trying to add a product to my basket using the high level API.
using UCommerce.Api;using Umbraco.Web.WebApi; namespace UCommerceSupport.CustomControllers{public class BasketApiController : UmbracoApiController{public void AddToBasket(int quantity, string sku){TransactionLibrary.AddToBasket(quantity, sku, variantSku: null, addToExistingLine: true, executeBasketPipeline: true, catalogId: null);}}}Then you can call your service at /umbraco/basketapi/AddToBasket with AJAX. This is actually first time looking into WebApi but it seems quite easy to pass objects from AJAX. Try to take a look at this:
http://stackoverflow.com/questions/10493111/asp-net-webapi-how-to-pass-object-with-getjson
If more questions just ask and I will try to answer :)
Best regards Martin
Edit: This forum seriously need a "codeblock" >.<
Thanks for the response, Martin. The code looks straight forward enough, my problem is how to reference UCommerce.Api namespace.
I've setup Umbraco in Visual Studio, the installed uCommerce via the package installation.
I then create an API controller but am unable to reference the uCommerce.Api namespace. Do I need to add uCommerce to my project like in this example? http://www.publicvoid.dk/CategoryView,category,uCommerce.aspx
Cheers,
David.
Yes you need to reference the assemblies you want to use.
I personally reference all uCommerce assemblies from my own assemblies if they're need in there. Otherwise if you have Resharper it tempts to take assemblies directly from bin folder in website (and that can be annoying if you're working on a team).
Edit:
uCommerce.Api lives specificly in ucommerce.dll
is working on a reply...