I have been working with the Chilkat Chilkat_9_5_0.Rest to connect to woocommerce API.
I can successfully retrieve a list of orders using this line of code -
responseJson = rest.FullRequestNoBody("GET","/wc-api/v3/orders/")
Now I need to be able to place an order using VBScript. Has anyone done this? I believe I need to call the same orders, but I cannot figure out how to sent the parameters I need to place the order. Does anyone have an example of doing this in VB Script with the Chilkat dll?
Thanks in advance!
Writing the Chilkat REST code to any REST API call should be fairly straightforward. Here's how I go about doing it...
First find the reference documentation for the REST API. In this case, the WooCommerce REST API reference documentation is at: http://woocommerce.github.io/woocommerce-rest-api-docs/#orders
Step 1 -- What is the HTTP Verb?
If just getting information, then it's likely a GET. If sending information, such as for placing an order, updating information, creating something, etc., then it would be a POST or GET. The DELETE HTTP verb would typically be used for deleting something. The service's REST API reference documentation should specify what verb to use. In this particular case, it's a POST.
Step 2 -- What is the Path?
What is the path part of the URI? Looking at the WooCommerce documentation for placing an order, the path is "/wp-json/wc/v1/orders".
Step 3: How is the information sent?
When a POST or PUT is used, the information of the request can be sent in a number of possible ways. Typical options are:
It may be that information is sent both in request headers and in the request body. It's also possible that a "GET" request could serve for sending information to the server if the information is contained in the GET request params on the URL, but this is less likely because the information is visible to the world..
Looking at the WooCommerce REST API documentation for placing an order, we can see that the order information is JSON that sent in the body of the request. For cases where the request body contains JSON or XML, the methods of chose are Rest.FullRequestSb or Rest.FullRequestString.
(If the information was passed in query params, then we'd choose the FullRequestFormUrlEncoded method.)
So... to place the WooCommerce order, you would first construct the JSON specifying the order data. Then call Rest.FullRequestString(string httpVerb, string uriPath, string bodyText).
In this case, the httpVerb = "POST".
The uriPath = "/wp-json/wc/v1/orders".
The bodyText contains the JSON for the order.
Don't forget to also set the Content-Type header for the request to "application/json" by calling Rest.AddHeader("Content-Type","application/json")
Step 4 -- The Response Finally, look at the service's REST API documentation (WooCommerce in this case) to see the expected response. What is the expected success response code? Is it 200, 201, 204? What is the format and location of the response information? In this case, the response information is JSON contained in the response body. If the response code is not clearly indicated, then accept either 200 or 201 as success. A 204 response is generally for success where there is no response data.