login about faq

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!

asked Mar 01 at 09:51

gpfeifer's gravatar image

gpfeifer
312

edited Mar 01 at 09:52


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:

  1. JSON or XML in the request body. In this case, the Content-Type of the HTTP request would typically be application/json or text/xml (or possibly application/xml).
  2. Request Parameters. In this case, the Content-Type is application/x-www-form-urlencoded, and request body is composed of the request parameters in URL encoded format (just like they would be in the URL for a GET request, but instead placed in the body of the request to eliminate size restrictions). Request parameters are added via the Chilkat.Rest.AddQueryParam method.
  3. HTTP Request Headers. In this case, information is sent in the MIME request header (i.e. they are header fields just like Content-Type is a header field). HTTP request headers are added via the Chilkat.Rest.AddHeader method.

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.

link

answered Mar 02 at 10:24

chilkat's gravatar image

chilkat ♦♦
12.8k317366475

edited Mar 02 at 10:25

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×19
×15

Asked: Mar 01 at 09:51

Seen: 348 times

Last updated: Mar 02 at 10:25

powered by OSQA