CJ dropshipping is one of the best dropshipping services available for eCommerce websites that run on a dropship model. One can use tools provided by CJ dropshipping to integrate with their Shopify, Magento or WooCommerce etc website. But there is always a gap for website build on ASP.NET C#. There is no utility or tool written for these websites. In addition to that, there is no inventory sync available.

CJ dropshipping

I have written a small program that let you connect with CJ dropshipping API and an open lot of possibilities. You can write a scheduled job to get products from API. you can manage inventory and pricing using this API and run your dropship website on true autopilot.

So let’s get to the work.

First of all, you need to go to CJ dropshipping account and create credentials for your API. Now add API access URL and Access token in the web.config

<appSettings>
		<add key="CjAccessUrl" value="https://developers.cjdropshipping.com/"/>
		<add key="CjAccessToken" value="your-access-token"/>
	</appSettings>

The next step is you need to create request and response objects.

I have created a request object that takes SKU and my response object gives me data results.

Request Object

public class CjRequestBody
    {
        public string sku { get; set; }
    }

Response Object

public class CjResponse
    {
        public bool Result { get; set; }
        public string Message { get; set; }
        public List<Data> Data { get; set; }
    }
    public class Data
    {
        public string Img { get; set; }
        public string ProductId { get; set; }
        public float ShortSku { get; set; }
        public string Price { get; set; }
        public double SellDiscount { get; set; }
        public string ShopId { get; set; }
        public string VariantId { get; set; }
        public string Title { get; set; }
        public string Sku { get; set; }
    }

Now we have everything we need to do a simple call to CJ dropshipping API and get product information

var cjShoppingClient = new RestClient(ConfigurationManager.AppSettings.Get("CjAccessUrl"));
            var cjShoppingSecret = ConfigurationManager.AppSettings.Get("CjAccessToken");
            var request = new RestRequest("api/product/connectList", Method.POST);
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("CJ-Access-Token", cjShoppingSecret);
            var requestBody = new CjRequestBody
            {
                sku = "CJYDQTJM01607-USB"
            };
            request.AddJsonBody(JsonConvert.SerializeObject(requestBody));
            var response = cjShoppingClient.Execute<CjResponse>(request);
            if (response.Data != null)
            {
                //Do something
            }

You can see in the above code we use CJ Access Url and Access token and call api/product/connect list API and get product information based on the given SKU.

This code is available on Github. Please feel free to download & enhance it.

Categorized in: