woocommerce/plugins/woocommerce-blocks/src/StoreApi
Sebastian Volland eac83ffed4 Add an early return to prevent running an invalid SQL query. (https://github.com/woocommerce/woocommerce-blocks/pull/4317) 2021-06-07 13:40:48 +01:00
..
Formatters Add Formatter Classes to the Store API for Extensions to Consume (https://github.com/woocommerce/woocommerce-blocks/pull/3503) 2020-12-03 19:17:03 +01:00
Routes Add cart/extensions endpoint to allow third party extensions to process server-side and get a new cart (https://github.com/woocommerce/woocommerce-blocks/pull/4298) 2021-06-07 12:16:47 +03:00
Schemas Add an early return to prevent running an invalid SQL query. (https://github.com/woocommerce/woocommerce-blocks/pull/4317) 2021-06-07 13:40:48 +01:00
Utilities Update design of cart and checkout sidebars (https://github.com/woocommerce/woocommerce-blocks/pull/4180) 2021-05-17 15:00:57 +01:00
docs Handle out of stock product visibility setting in All Products block. (https://github.com/woocommerce/woocommerce-blocks/pull/3859) 2021-02-18 10:53:48 +01:00
Formatters.php Add Formatter Classes to the Store API for Extensions to Consume (https://github.com/woocommerce/woocommerce-blocks/pull/3503) 2020-12-03 19:17:03 +01:00
README.md Sync shipping address with billing address when shipping address fields are disabled (https://github.com/woocommerce/woocommerce-blocks/pull/3358) 2020-11-20 15:13:35 +00:00
RoutesController.php Add cart/extensions endpoint to allow third party extensions to process server-side and get a new cart (https://github.com/woocommerce/woocommerce-blocks/pull/4298) 2021-06-07 12:16:47 +03:00
SchemaController.php Add cart/extensions endpoint to allow third party extensions to process server-side and get a new cart (https://github.com/woocommerce/woocommerce-blocks/pull/4298) 2021-06-07 12:16:47 +03:00

README.md

WooCommerce Store API

The WooCommerce Store API is a public-facing (for internal use only currently) REST API. Unlike the main WooCommerce REST API, this API does not require authentication and is intended to be used by customer facing client side code.

This documentation assumes knowledge of REST concepts.

Current status

This API is used internally by Blocks--it is still in flux and may be subject to revisions. There is currently no versioning system, and this API should therefore be used at your own risk. Eventually, it will be moved to the main WooCommerce REST API at which point it will be versioned and safe to use in other projects.

Basic usage

Example of a valid API request using cURL:

curl "https://example-store.com/wp-json/wc/store/products"

The API uses JSON to serialize data. You dont need to specify .json at the end of an API URL.

Namespace

Resources in the Store API are all found within the wc/store/ namespace, and since this API extends the WordPress API, accessing it requires the /wp-json/ base. Examples:

GET /wp-json/wc/store/products
GET /wp-json/wc/store/cart

Authentication

Requests to the store API do not require authentication. Only public data is returned, and most endpoints are read-only, with the exception of the cart API which only lets you manipulate data for the current session, and requires a nonce token.

Status codes

The following table gives an overview of how the API functions generally behave.

Request type Description
GET Access one or more resources and return 200 OK and the result as JSON.
POST Return 201 Created if the resource is successfully created and return the newly created resource as JSON.
PUT Return 200 OK if the resource is modified successfully. The modified result is returned as JSON.
DELETE Returns 204 No Content if the resource was deleted successfully.

The following table shows the possible return codes for API requests.

Response code Description
200 OK The request was successful, the resource(s) itself is returned as JSON.
204 No Content The server has successfully fulfilled the request and that there is no additional content to send in the response payload body.
201 Created The POST request was successful and the resource is returned as JSON.
400 Bad Request A required attribute of the API request is missing.
403 Forbidden The request is not allowed.
404 Not Found A resource could not be accessed, for example it doesn't exist.
405 Method Not Allowed The request is not supported.
409 Conflict The request could not be completed due to a conflict with the current state of the target resource. The current state may also be returned.
500 Server Error While handling the request something went wrong server-side.

Pagination

If collections contain many results, they may be paginated. When listing resources you can pass the following parameters:

Parameter Description
page Current page of the collection. Defaults to 1.
per_page Maximum number of items to be returned in result set. Defaults to 10. Maximum 100.

In the example below, we list 20 products per page and return page 2.

curl "https://example-store.com/wp-json/wc/store/products?page=2&per_page=20"

Pagination headers

Additional pagination headers are also sent back.

Header Description
X-WP-Total The total number of items in the collection.
X-WP-TotalPages The total number of pages in the collection.
Link Contains links to other pages; next, prev, and up where applicable.

API resources and endpoints

Available resources in the Store API are listed below, with links to more detailed documentation.

Resource Available endpoints
Cart /wc/store/cart
/wc/store/cart/add-item
/wc/store/cart/remove-item
/wc/store/cart/update-item
/wc/store/cart/apply-coupon
/wc/store/cart/remove-coupon
/wc/store/cart/update-customer
/wc/store/cart/select-shipping-rate
Cart Items /wc/store/cart/items
Cart Coupons /wc/store/cart/coupons
Checkout /wc/store/checkout
Products /wc/store/products
Product Collection Data /wc/store/products/collection-data
Product Attributes /wc/store/products/attributes
Product Attribute Terms /wc/store/products/attributes/1/terms