How to use JSON.NET in WooCommerce.NET - XiaoFaye/WooCommerce.NET GitHub Wiki

  1. Make sure you get WooCommerce.NET version 0.7.1 or higher from NuGet.org.
  2. Add Json.NET reference to your project.
  3. Define your own RESTAPI class as below:
    public class MyRestAPI : RestAPI
    {
        public MyRestAPI(string url, string key, string secret, bool authorizedHeader = true, 
            Func<string, string> jsonSerializeFilter = null, 
            Func<string, string> jsonDeserializeFilter = null, 
            Action<HttpWebRequest> requestFilter = null) : base(url, key, secret, authorizedHeader, jsonSerializeFilter, jsonDeserializeFilter, requestFilter)
        {
        }

        public override T DeserializeJSon<T>(string jsonString)
        {
            return JsonConvert.DeserializeObject<T>(jsonString);
        }

        public override string SerializeJSon<T>(T t)
        {
            return JsonConvert.SerializeObject(t);
        }
    }
  1. Now use your RESTAPI class to make Restful calls
using WooCommerceNET.WooCommerce.v2;
using WooCommerceNET.WooCommerce.v2.Extension;

MyRestAPI rest = new MyRestAPI("http://www.yourstore.co.nz/wp-json/wc/v2/", "<WooCommerce Key>", "<WooCommerce Secret");
WCObject wc = new WCObject(rest);

//Get all products
var products = await wc.Product.GetAll();