We make the assumption that you are comfortable with REST API’s and understand the basics of WordPress and WooCommerce. Since they are both (including CoCart) are built in PHP, we recommend having some knowledge of it as well.
Base url
The base URL is where your WordPress is installed. All requests made to CoCart API is via your WordPress site urlhttps://example-store.com/wp-json/cocart/
Request/Response Format
The default response format is in JSON. Requests with a message-body use plain JSON to set or update resource attributes. Successful requests will return a200 OK HTTP status.
Some general information about response:
- Resource IDs are returned as integers.
- Other number values, such as price, item counts, are returned as integers or strings.
- Blank fields may return as
nullinstead of being returned as blank strings or omitted.
Body Types
There are different types of body types when making a request. Make sure when using either of these body types that you have the correctContent-Type for the header.
Using raw works best if you are passing an object of data for a
variation or cart_item_data. Use any of the tools available to help test the API with if you are unsure.
Errors
Occasionally you might encounter errors when accessing the REST API. Here are the possible types:WP REST API error example
CoCart error example
code, message and data attribute.