CoCart Core v5 is not yet published as it is still in development but feel free to review the API Reference for it and provide feedback on breaking changes and improvements. Beta releases will be out soon.
While the API reference for version 1 remains documented, it will no longer be supported starting with CoCart Core v5. We highly recommend that you use API v2. Please contact support if you need help transitioning over.
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
null
instead 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.
Body Type | Content-Type |
---|---|
form-data | application/json |
raw | application/json |
x-www-form-urlencoded | application/x-www-form-urlencoded |
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:Error Code | Error Type |
---|---|
400 Bad Request | Invalid request, e.g. using an unsupported HTTP method. |
401 Unauthorized | Authentication or permission error, e.g. incorrect login. |
403 Forbidden | Not allowed to process this action or have permission. |
404 Not Found | Requests to resources that don’t exist or are missing. |
405 Method Not Allowed | A request method is not supported for the requested resource. |
406 Not Acceptable | Indicates that the server could not produce a response. |
500 Internal Server Error | Server error |
WP REST API error example
CoCart error example
code
, message
and data
attribute.