Shyam sundar shah
Shyam sundar shah

Reputation: 2523

how to get List of Orders from Woocommerce API?

I am trying to get list of orders from Woocommerce using Latest REST API v3. I am using Basic Authentication. It is said that Woocommerce Supports basic Authentication for Https (SSL enable).

My code is below .

        WebRequest myReq = (HttpWebRequest)WebRequest.Create("https://shyamssaging.com:443/woocommerce/wc-api/v3/orders");
        string usernamePassword = "ck_255fd4ab5dfb235065932b5ed72f419a8c2659e2:cs_7f619115423ff9d9b845fca8ee7053ff01c4ab27";            
        myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(usernamePassword)));            
        WebResponse wr = myReq.GetResponse();
        Stream receiveStream = wr.GetResponseStream();
        StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
        string content = reader.ReadToEnd();

Error is Unauthorized. Even, i am using valid Userkey and secret key . Thanks Shyams

Upvotes: 0

Views: 4990

Answers (1)

Anand Shah
Anand Shah

Reputation: 14913

There's a REST API Client Library you can find here , you'll need to make minor changes to the code.

  1. Create a new class in your application called WoocommerceApiClient.cs and paste the code from the link above in it ( as I already mentioned you need to make minor changes )
  2. You can then reference it using

    string ConsumerKey = "key";
    string ConsumerSecret = "secret";
    string StoreUrl = "https://www.fishbowlstaging.com";
    bool Isssl = true;
    
    WoocommerceApiClient client = new WoocommerceApiClient(ConsumerKey, ConsumerSecret, StoreUrl, Isssl);
    string orders = client.GetProducts();
    

You can add more methods to the class as you require.

Upvotes: 1

Related Questions