I want to update order status through Woocommerce REST Api V2 in my windows service project. I got a sample C# code to download orders from this link
Consuming WooCommerce REST API from C#
Its working fine as I am downloading orders from my local server.
But I want to update order/add order note.
I tried this
public string UpdateOrder()
{
//return MakeApiCall_mine("orders/17", new Dictionary<string, string>() { { "order", "{"status":"completed"}" } });//
return MakeApiCall_mine("orders/17");
}
private string MakeApiCall_mine(string endpoint, Dictionary<string, string> parameters = null, string method = "PUT")
{
if (parameters == null)
{
parameters = new Dictionary<string, string>();
}
parameters["oauth_consumer_key"] = this.ConsumerKey;
parameters["oauth_timestamp"] =
DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds.ToString();
parameters["oauth_timestamp"] = parameters["oauth_timestamp"].Substring(0,
parameters["oauth_timestamp"].IndexOf("."));
parameters["oauth_nonce"] = Hash(parameters["oauth_timestamp"]);
parameters["oauth_signature_method"] = "HMAC-SHA256";
parameters["oauth_signature"] = GenerateSignature(parameters, method, endpoint);
WebClient wc = new WebClient();
StringBuilder sb = new StringBuilder();
foreach (var pair in parameters)
{
sb.AppendFormat("&{0}={1}", HttpUtility.UrlEncode(pair.Key), HttpUtility.UrlEncode(pair.Value));
}
var url = this.ApiUrl + endpoint + "?" + sb.ToString().Substring(1).Replace("%5b", "%5B").Replace("%5d", "%5D");
//var result = wc.DownloadString(url);
wc.UploadString(url, "{"order":{"status":"completed"}}");
//return result;
return "";
}
but getting error The remote server returned an error: (401) Unauthorized
My woocommerce user Permissions:Read/Write.