简体   繁体   中英

Woocommerce REST API POST in v2 not working

I have upgraded to V2 and having trouble with posting updates to Woocommerce on my Windows server from C# (using RestSharp).

GET works in both V1 and V2.

Changing order status (for order 81) works in V1, using this code:

var client = new RestClient("https://mysite.com");
client.Authenticator = new HttpBasicAuthenticator("ck_6c5bbb4e467d1994d2428a476bxxxxxx",
                                              "cs_008adefb1692a708e9795de9fxxxxxx");
var requestv1 = new RestRequest("wc-api/v1/orders/{id}", Method.POST);
requestv1.RequestFormat = DataFormat.Json;
requestv1.AddBody(new { status = "completed" }); 
requestv1.AddParameter("id", 81, ParameterType.UrlSegment);
var queryResultv1 = client.Execute<WC_Manager.OrderSingle>(requestv1);

Changing the resource to "wc-api/v2/orders/{id}" generates no error and the Execute still returns the order now with the extra fields from v2, however the status is NOT changed in the queryresult or in the database.
Same problem when trying to post an update for a product in V2.

Trying to PUT or DELETE gives me a "MethodNotAllowed".

You can add body content with this:

string bodyContent;
bodyContent = "{ \"status\": \"completed\" , ";
bodyContent += "\"customer_note\": \"" + customerNote + "\" }";    
request.AddParameter("application/json", bodyContent, ParameterType.RequestBody);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM